Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - mdd333

Pages: [1]
1
Audio / Re: OpenAL unhandled exception after trying to play some sound
« on: February 19, 2017, 06:42:37 pm »
Ah my apologies, I figured out the problem and successfully fixed it. Turns out I shouldn't really be freeing musicData inside the onGetData function (the docs say I should do it *after* it's called, my bad).

2
Audio / OpenAL unhandled exception after trying to play some sound
« on: February 19, 2017, 06:10:36 pm »
Hello.

So I've tried to make my own custom soundbuffer class, but I'm having trouble playing the audio I send to it. The program seems to work fine, the onGetData function and returns with no errors, but after a tiny bit I get an error:

Quote
Unhandled exception at 0x0F8E78E6 (openal32.dll) in cbsp-vs.exe: 0xC0000005: Access violation reading location 0x0B7DC040.

I'm running on Windows 10, Visual Studio 2015 and am using SFML 2.4.2 (Visual C++ 14 (2015) - 32-bit version from the website).

This is the code I've used in my MusicPlayer (custom audiostream) class:

void MusicPlayer::StartTrack(string track, int loopstart, int looplength) //loads music track data and initializes stream
{
        curSample = 0;
        loopStart = loopstart;
        loopLength = looplength;
        trackName = track;
        sf::Int16* musicData = (sf::Int16*)BDP::ReadBDP(trackName, 0, 44); //load only the header
        sampleCount = BitConv::FromInt32((uint8_t*)musicData, 40) / 2; //WARNING: Samples MUST be 16-bit!
        short int channelCount = BitConv::FromInt16((uint8_t*)musicData, 22);
        int sampleRate = BitConv::FromInt32((uint8_t*)musicData, 24);
        initialize(channelCount, sampleRate);
        free(musicData);
}
bool MusicPlayer::onGetData(Chunk& data)
{
        sf::Int16* musicData;
        if (curSample + BUFFER_LENGTH / 2 >= sampleCount)
        {  //only add to buffer the remaining samples
                int remainSamples = sampleCount - curSample;
                musicData = (sf::Int16*)BDP::ReadBDP(trackName, 44 + curSample * 2, remainSamples * 2);
                data.samples = (sf::Int16*)musicData;
                data.sampleCount = remainSamples;
                curSample = loopStart;
        }
        else
        {  //add to buffer all available samples
                musicData = (sf::Int16*)BDP::ReadBDP(trackName, 44 + curSample * 2, BUFFER_LENGTH);
                data.samples = (sf::Int16*)musicData;
                data.sampleCount = BUFFER_LENGTH / 2;
                curSample += BUFFER_LENGTH / 2;
        }
        free(musicData);
        return true;
}

And this is the code that I'm using to play it:
                                musicPlayer.StartTrack("snd/mus/menu.wav", 276706, 3251294);
                                musicPlayer.play();
(unsurprisingly it's just those 2 lines)

Thank you for your help.

EDIT: The ReadBDP function just reads a file (which is inside a bigger file) and it works perfectly, so pretend that I'm just reading a file (or part of it since I can specify offset and size to read from the file, which I did here in order to just read the sample data from a WAV).

Pages: [1]
anything