|
View:
New views
8 Messages
—
Rating Filter:
Alert me
|
|
|
|
|
|
Split wav channelHello, I'm new user of OpenAl and i need to make spatial a wave with stereo channel. I thought I can split it in two separated sources and make these spatial. But How can I split the 2 channel? Thanks, Huvber _______________________________________________ Openal mailing list Openal@... http://opensource.creative.com/mailman/listinfo/openal |
|
|
Re: Split wav channelAndrea Mannarà wrote:
> Hello, > I'm new user of OpenAl and i need to make spatial a wave with stereo > channel. > I thought I can split it in two separated sources and make these spatial. > But How can I split the 2 channel? There isn't a way to do this by using only OpenAL. A buffer with multiple channels will not be spatialized by OpenAL, and there isn't any way to split or combine the channels inside OpenAL itself. Your best bet is to use a sound editing tool to convert the sound from stereo to mono, and then load that into OpenAL to do your spatialization. If you really do need the stereo sound to be spatialized (this doesn't really make sense, except in a few special cases), you can use the sound editing tool to save out each channel of the stereo sound separately, and then create two sources (one for left, one for right), and position them appropriately. --"J" _______________________________________________ Openal mailing list Openal@... http://opensource.creative.com/mailman/listinfo/openal |
|
|
Re: Split wav channelHi, Stereo wave files have interleaved data i.e a Left Channel Sample followed by a Right Channel Sample followed by Left, Right etc ... If you want to split the file into two monos then you would do something like this (assuming 16bit samples and that the pointers are all valid and point to enough storage space, etc ...) ALvoid SplitStereo(ALshort *pStereoData, ALshort *pLeft, ALshort *pRight, ALuint uiNumSamples) { ALuint i; for (i = 0; i < uiNumSamples; i++) { pLeft[ i ] = pStereoData[i*2]; pRight[ i ] = pStereoData[i*2+1]; } } If you just want to create a single mono stream from a stereo file, then you need to mix the Left and Right samples together (and watch out for overflows). ALvoid StereoToMono(ALshort *pStereoData, ALshort *pMonoData, ALuint uiNumSamples) { ALuint i; ALint result; for (i = 0; i< uiNumSamples; i++) { result = (ALint)pStereoData[i*2] + (ALint)pStereoData[i*2+1]; if (result > 32767) result = 32767; else if (result < -32768) result = -32768; pMonoData[i] = (ALshort)result; } } NOTE : uiNumSamples is the number of 'blocks' or 'frames' and not the count of all the samples in all the channels. e.g. For 16bit stereo data, uiNumSamples = DataSizeInBytes / 4. (divide by 2 because it is 16bit shorts, and divide by 2 again because there are 2 channels). If you intend to play both mono parts of the stereo file then you should use the vector play call (alSourcePlayv) to keep the parts in sync otherwise you might hear some strange artifacts. Dan Creative Labs (UK) Ltd. Notice The information in this message is confidential and may be legally privileged. It is intended solely for the addressee. Access to this message by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying or distribution of the message, or any action taken by you in reliance on it, is prohibited and may be unlawful. If you have received this message in error, please delete it and contact the sender immediately. Thank you. Creative Labs UK Ltd company number 2658256 registered in England and Wales at Belmont Road, Belmont Place, Maidenhead, Berkshire, SL6 6TB Andrea Mannarà <andrea.mannara@t hesis.seac02.it> To Sent by: openal@... openal-bounces@op cc ensource.creative .com Subject [Openal] Split wav channel 07/28/2009 02:00 PM Hello, I'm new user of OpenAl and i need to make spatial a wave with stereo channel. I thought I can split it in two separated sources and make these spatial. But How can I split the 2 channel? Thanks, Huvber _______________________________________________ Openal mailing list Openal@... http://opensource.creative.com/mailman/listinfo/openal ForwardSourceID:NT0006E24A _______________________________________________ Openal mailing list Openal@... http://opensource.creative.com/mailman/listinfo/openal |
|
|
|
|
|
Re: Split wav channelsorry for the lot of mail but it's my first mailing list.
On Tue, Jul 28, 2009 at 5:52 PM, Daniel PEACOCK <dpeacock@...> wrote: > > Hi, > > Stereo wave files have interleaved data i.e a Left Channel Sample followed by a Right Channel Sample followed by Left, Right etc ... If you want to split the file into two monos then you would do something like this (assuming 16bit samples and that the pointers are all valid and point to enough storage space, etc ...) > > ALvoid SplitStereo(ALshort *pStereoData, ALshort *pLeft, ALshort *pRight, ALuint uiNumSamples) > { > ALuint i; > > for (i = 0; i < uiNumSamples; i++) > { > pLeft[ i ] = pStereoData[i*2]; > pRight[ i ] = pStereoData[i*2+1]; > } > } > > If you just want to create a single mono stream from a stereo file, then you need to mix the Left and Right samples together (and watch out for overflows). > > ALvoid StereoToMono(ALshort *pStereoData, ALshort *pMonoData, ALuint uiNumSamples) > { > ALuint i; > ALint result; > > for (i = 0; i< uiNumSamples; i++) > { > result = (ALint)pStereoData[i*2] + (ALint)pStereoData[i*2+1]; > if (result > 32767) > result = 32767; > else if (result < -32768) > result = -32768; > pMonoData[i] = (ALshort)result; > } > } > > NOTE : uiNumSamples is the number of 'blocks' or 'frames' and not the count of all the samples in all the channels. e.g. For 16bit stereo data, uiNumSamples = DataSizeInBytes / 4. (divide by 2 because it is 16bit shorts, and divide by 2 again because there are 2 channels). > > If you intend to play both mono parts of the stereo file then you should use the vector play call (alSourcePlayv) to keep the parts in sync otherwise you might hear some strange artifacts. > > Dan > Creative Labs (UK) Ltd. Hi, Thanks a lot for your help, but I'm still in trouble. I post my code: ALvoid SplitStereo(ALshort *pStereoData, ALshort *pLeft, ALshort *pRight, ALuint uiNumSamples) { ALuint i; if(pLeft == NULL) pLeft = (ALshort *) malloc(uiNumSamples*2); if(pRight == NULL) pRight = (ALshort *) malloc(uiNumSamples*2); for (i = 0; i < uiNumSamples; i++) { pLeft[ i ] = pStereoData[i*2]; pRight[ i ] = pStereoData[i*2+1]; } } ALenum format; ALsizei size; ALfloat freq; ALboolean loop; ALuint bufferL; ALuint bufferR; ALshort *alDataR=NULL; ALshort *alDataL = NULL alDataR =(ALshort *) alutLoadMemoryFromFile ((ALbyte*)&(getUrl(i))[0], &format, &size, &freq); if( alDataR ) { if(format == AL_FORMAT_STEREO16) { SplitStereo((ALshort*)alDataR,(ALshort*)alDataL,(ALshort*)alDataR, size/4); alGenBuffers(1, &bufferL); alGenBuffers(1, &bufferR); alBufferData( bufferL, AL_FORMAT_MONO8, alDataL, size/4, freq ); alBufferData( bufferR, AL_FORMAT_MONO8, alDataR, size/4, freq ); }else{ alGenBuffers( 1, &bufferR ); alBufferData( bufferR, format, alDataR, size, freq ); setStorage_id( bufferR); setL(0); } alSourceQueueBuffers( soundId1 , 1, (ALuint*)&(bufferR) ); alSourceQueueBuffers( soundId2 , 1, (ALuint*)&(bufferL) ); alSourcePlay( soundId1 ); alSourcePlay( soundId2 ); } if the wav is in mono i haven't problem. Otherwise if i use a wav stereo i have a noise similar to white noise. Why? _______________________________________________ Openal mailing list Openal@... http://opensource.creative.com/mailman/listinfo/openal |
|
|
Re: Split wav channelHi Andrea, I think there are few issues here. 1. This routine ... ALvoid SplitStereo(ALshort *pStereoData, ALshort *pLeft, ALshort *pRight, ALuint uiNumSamples) { ALuint i; if(pLeft == NULL) pLeft = (ALshort *) malloc(uiNumSamples*2); if(pRight == NULL) pRight = (ALshort *) malloc(uiNumSamples*2); for (i = 0; i < uiNumSamples; i++) { pLeft[ i ] = pStereoData[i*2]; pRight[ i ] = pStereoData[i*2+1]; } } If you want this function to allocate memory when needed, then you will need to pass in pointers to pointers for the left and right buffers. In your code alDataL will still be NULL after calling the function - and you will leak memory. alDataR will actually be OK, because it is non-NULL on entry (it actually points to the stereo interleaved data, i.e same as pStereoData). I would expect you to get an AL error when doing alBufferData( bufferL, AL_FORMAT_MONO8, alDataL, size/4, freq ); because alDataL is NULL. 2. The alBufferData calls have 2 other problems ... AL_FORMAT_MONO8 should be replaced by AL_FORMAT_MONO16 (we didn't change the bit depth just the channel count - this is what is causing the random noise). Also the 4th parameter should be the number of bytes not samples - which in this case will be size / 2. Try those modifications and see what happens. Dan Creative Labs (UK) Ltd. Notice The information in this message is confidential and may be legally privileged. It is intended solely for the addressee. Access to this message by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying or distribution of the message, or any action taken by you in reliance on it, is prohibited and may be unlawful. If you have received this message in error, please delete it and contact the sender immediately. Thank you. Creative Labs UK Ltd company number 2658256 registered in England and Wales at Belmont Road, Belmont Place, Maidenhead, Berkshire, SL6 6TB Andrea Mannarà <andrea.mannara@t hesis.seac02.it> To Sent by: openal@... openal-bounces@op cc ensource.creative .com Subject [Openal] Split wav channel 07/29/2009 11:25 AM ---------- Forwarded message ---------- From: Huvber <huvber@...> Date: Wed, Jul 29, 2009 at 12:23 PM Subject: Re: [Openal] Split wav channel To: Daniel PEACOCK <dpeacock@...> Cc: openal@... On Tue, Jul 28, 2009 at 5:52 PM, Daniel PEACOCK <dpeacock@...> wrote: > > Hi, > > Stereo wave files have interleaved data i.e a Left Channel Sample followed by a Right Channel Sample followed by Left, Right etc ... If you want to split the file into two monos then you would do something like this (assuming 16bit samples and that the pointers are all valid and point to enough storage space, etc ...) > > ALvoid SplitStereo(ALshort *pStereoData, ALshort *pLeft, ALshort *pRight, ALuint uiNumSamples) > { > ALuint i; > > for (i = 0; i < uiNumSamples; i++) > { > pLeft[ i ] = pStereoData[i*2]; > pRight[ i ] = pStereoData[i*2+1]; > } > } > > If you just want to create a single mono stream from a stereo file, then overflows). > > ALvoid StereoToMono(ALshort *pStereoData, ALshort *pMonoData, ALuint uiNumSamples) > { > ALuint i; > ALint result; > > for (i = 0; i< uiNumSamples; i++) > { > result = (ALint)pStereoData[i*2] + (ALint)pStereoData[i*2+1]; > if (result > 32767) > result = 32767; > else if (result < -32768) > result = -32768; > pMonoData[i] = (ALshort)result; > } > } > > NOTE : uiNumSamples is the number of 'blocks' or 'frames' and not the uiNumSamples = DataSizeInBytes / 4. (divide by 2 because it is 16bit shorts, and divide by 2 again because there are 2 channels). > > If you intend to play both mono parts of the stereo file then you should use the vector play call (alSourcePlayv) to keep the parts in sync otherwise you might hear some strange artifacts. > > Dan > Creative Labs (UK) Ltd. Hi, Thanks a lot for your help, but I'm still in trouble. I post my code: ALvoid SplitStereo(ALshort *pStereoData, ALshort *pLeft, ALshort *pRight, ALuint uiNumSamples) { ALuint i; if(pLeft == NULL) pLeft = (ALshort *) malloc(uiNumSamples*2); if(pRight == NULL) pRight = (ALshort *) malloc(uiNumSamples*2); for (i = 0; i < uiNumSamples; i++) { pLeft[ i ] = pStereoData[i*2]; pRight[ i ] = pStereoData[i*2+1]; } } ALenum format; ALsizei size; ALfloat freq; ALboolean loop; ALuint bufferL; ALuint bufferR; ALshort *alDataR=NULL; ALshort *alDataL = NULL alDataR =(ALshort *) alutLoadMemoryFromFile ((ALbyte*)&(getUrl(i))[0], &format, &size, &freq); if( alDataR ) { if(format == AL_FORMAT_STEREO16) { SplitStereo((ALshort*)alDataR,(ALshort*)alDataL,(ALshort*)alDataR, size/4); alGenBuffers(1, &bufferL); alGenBuffers(1, &bufferR); alBufferData( bufferL, AL_FORMAT_MONO8, alDataL, size/4, freq ); alBufferData( bufferR, AL_FORMAT_MONO8, alDataR, size/4, freq ); }else{ alGenBuffers( 1, &bufferR ); alBufferData( bufferR, format, alDataR, size, freq ); setStorage_id( bufferR); setL(0); } alSourceQueueBuffers( soundId1 , 1, (ALuint*)&(bufferR) ); alSourceQueueBuffers( soundId2 , 1, (ALuint*)&(bufferL) ); alSourcePlay( soundId1 ); alSourcePlay( soundId2 ); } if the wav is in mono i haven't problem. Otherwise if i use a wav stereo i have a noise similar to white noise. Why? _______________________________________________ Openal mailing list Openal@... http://opensource.creative.com/mailman/listinfo/openal ForwardSourceID:NT0006E2AE _______________________________________________ Openal mailing list Openal@... http://opensource.creative.com/mailman/listinfo/openal |
|
|
Re: Re: Split wav channelOk it's working thanks a lot.
On Wed, Jul 29, 2009 at 12:53 PM, Daniel PEACOCK<dpeacock@...> wrote: > Hi Andrea, > > I think there are few issues here. > > 1. This routine ... > > ALvoid SplitStereo(ALshort *pStereoData, ALshort *pLeft, ALshort > *pRight, ALuint uiNumSamples) > { > ALuint i; > if(pLeft == NULL) > pLeft = (ALshort *) malloc(uiNumSamples*2); > if(pRight == NULL) > pRight = (ALshort *) malloc(uiNumSamples*2); > for (i = 0; i < uiNumSamples; i++) > { > pLeft[ i ] = pStereoData[i*2]; > pRight[ i ] = pStereoData[i*2+1]; > } > } > > If you want this function to allocate memory when needed, then you will need > to pass in pointers to pointers for the left and right buffers. In your code > alDataL will still be NULL after calling the function - and you will leak > memory. alDataR will actually be OK, because it is non-NULL on entry (it > actually points to the stereo interleaved data, i.e same as pStereoData). I > would expect you to get an AL error when doing alBufferData( bufferL, > AL_FORMAT_MONO8, alDataL, size/4, freq ); because alDataL is NULL. > > 2. The alBufferData calls have 2 other problems ... AL_FORMAT_MONO8 should > be replaced by AL_FORMAT_MONO16 (we didn't change the bit depth just the > channel count - this is what is causing the random noise). Also the 4th > parameter should be the number of bytes not samples - which in this case > will be size / 2. > > Try those modifications and see what happens. > > Dan > Creative Labs (UK) Ltd. > > ________________________________ > Notice > The information in this message is confidential and may be legally > privileged. It is intended solely for the addressee. Access to this message > by anyone else is unauthorized. If you are not the intended recipient, any > disclosure, copying or distribution of the message, or any action taken by > you in reliance on it, is prohibited and may be unlawful. If you have > received this message in error, please delete it and contact the sender > immediately. Thank you. > > Creative Labs UK Ltd company number 2658256 registered in England and Wales > at Belmont Road, Belmont Place, Maidenhead, Berkshire, SL6 6TB > > Andrea Mannarà <andrea.mannara@...> > > > Andrea Mannarà <andrea.mannara@...> > Sent by: openal-bounces@... > > 07/29/2009 11:25 AM > > To > openal@... > cc > > Subject > [Openal] Split wav channel > ---------- Forwarded message ---------- > From: Huvber <huvber@...> > Date: Wed, Jul 29, 2009 at 12:23 PM > Subject: Re: [Openal] Split wav channel > To: Daniel PEACOCK <dpeacock@...> > Cc: openal@... > > > On Tue, Jul 28, 2009 at 5:52 PM, Daniel PEACOCK > <dpeacock@...> wrote: >> >> Hi, >> >> Stereo wave files have interleaved data i.e a Left Channel Sample followed >> by a Right Channel Sample followed by Left, Right etc ... If you want to >> split the file into two monos then you would do something like this >> (assuming 16bit samples and that the pointers are all valid and point to >> enough storage space, etc ...) >> >> ALvoid SplitStereo(ALshort *pStereoData, ALshort *pLeft, ALshort *pRight, >> ALuint uiNumSamples) >> { >> ALuint i; >> >> for (i = 0; i < uiNumSamples; i++) >> { >> pLeft[ i ] = pStereoData[i*2]; >> pRight[ i ] = pStereoData[i*2+1]; >> } >> } >> >> If you just want to create a single mono stream from a stereo file, then >> you need to mix the Left and Right samples together (and watch out for >> overflows). >> >> ALvoid StereoToMono(ALshort *pStereoData, ALshort *pMonoData, ALuint >> uiNumSamples) >> { >> ALuint i; >> ALint result; >> >> for (i = 0; i< uiNumSamples; i++) >> { >> result = (ALint)pStereoData[i*2] + (ALint)pStereoData[i*2+1]; >> if (result > 32767) >> result = 32767; >> else if (result < -32768) >> result = -32768; >> pMonoData[i] = (ALshort)result; >> } >> } >> >> NOTE : uiNumSamples is the number of 'blocks' or 'frames' and not the >> count of all the samples in all the channels. e.g. For 16bit stereo data, >> uiNumSamples = DataSizeInBytes / 4. (divide by 2 because it is 16bit shorts, >> and divide by 2 again because there are 2 channels). >> >> If you intend to play both mono parts of the stereo file then you should >> use the vector play call (alSourcePlayv) to keep the parts in sync otherwise >> you might hear some strange artifacts. >> >> Dan >> Creative Labs (UK) Ltd. > > Hi, > Thanks a lot for your help, but I'm still in trouble. I post my code: > > ALvoid SplitStereo(ALshort *pStereoData, ALshort *pLeft, ALshort > *pRight, ALuint uiNumSamples) > { > ALuint i; > if(pLeft == NULL) > pLeft = (ALshort *) malloc(uiNumSamples*2); > if(pRight == NULL) > pRight = (ALshort *) malloc(uiNumSamples*2); > for (i = 0; i < uiNumSamples; i++) > { > pLeft[ i ] = pStereoData[i*2]; > pRight[ i ] = pStereoData[i*2+1]; > } > } > > > > > ALenum format; > ALsizei size; > ALfloat freq; > ALboolean loop; > ALuint bufferL; > ALuint bufferR; > ALshort *alDataR=NULL; > ALshort *alDataL = NULL > alDataR =(ALshort *) alutLoadMemoryFromFile ((ALbyte*)&(getUrl(i))[0], > > &format, > > &size, > > &freq); > if( alDataR ) > { > if(format == AL_FORMAT_STEREO16) > { > > SplitStereo((ALshort*)alDataR,(ALshort*)alDataL,(ALshort*)alDataR, > size/4); > alGenBuffers(1, &bufferL); > alGenBuffers(1, &bufferR); > alBufferData( bufferL, AL_FORMAT_MONO8, alDataL, size/4, freq > ); > alBufferData( bufferR, AL_FORMAT_MONO8, alDataR, size/4, freq > ); > }else{ > alGenBuffers( 1, &bufferR ); > alBufferData( bufferR, format, alDataR, size, freq ); > setStorage_id( bufferR); > setL(0); > } > alSourceQueueBuffers( soundId1 , 1, (ALuint*)&(bufferR) ); > alSourceQueueBuffers( soundId2 , 1, (ALuint*)&(bufferL) ); > alSourcePlay( soundId1 ); > alSourcePlay( soundId2 ); > } > > if the wav is in mono i haven't problem. Otherwise if i use a wav > stereo i have a noise similar to white noise. > Why? > > _______________________________________________ > Openal mailing list > Openal@... > http://opensource.creative.com/mailman/listinfo/openal > > ForwardSourceID:NT0006E2AE > _______________________________________________ Openal mailing list Openal@... http://opensource.creative.com/mailman/listinfo/openal |
| Free embeddable forum powered by Nabble | Forum Help |