Author Topic: mixing to 16kHz mono but get 96kHz mono  (Read 115 times)

jakob

  • Posts: 105
mixing to 16kHz mono but get 96kHz mono
« on: 2 Nov '17 - 11:02 »
hi all
i have a decoder that takes whatever audio you give it, and converts it to 16bit 16kHz mono output.
now, the input audio that i have is 48kHz stereo m4a.
the result i get is 16bit mono, but the samplingrate is 96kHz. how do i change the sampling rate to 16KHz.
This is what i do:
Code: [Select]
stop = false;
int mixHandle = BassMix.BASS_Mixer_StreamCreate(16000, 1, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_MIXER_END);
BassMix.BASS_Mixer_StreamAddChannel(mixHandle, decodingStream.Handle, BASSFlag.BASS_DEFAULT);
int encodeHandle = BassEnc.BASS_Encode_Start(decodingStream.Handle, null, BASSEncode.BASS_ENCODE_PCM | BASSEncode.BASS_ENCODE_AUTOFREE | BASSEncode.BASS_ENCODE_NOHEAD | BASSEncode.BASS_ENCODE_LIMIT, null, IntPtr.Zero);

int bytesRead = 0;
MemoryStream ms = null;

while (Bass.BASS_ChannelIsActive(decodingStream.Handle) == BASSActive.BASS_ACTIVE_PLAYING || bytesRead != 0)
{
if (stop)
{
LogWriter.WriteLine("Decoding stopped on purpose");
break;
}

byte[] buf = new byte[4096];
bytesRead = Bass.BASS_ChannelGetData(decodingStream.Handle, buf, buf.Length);
if (bytesRead == -1)
{
BASSError error = Bass.BASS_ErrorGetCode();
if (error != BASSError.BASS_ERROR_ENDED)
LogWriter.WriteLine("Bass error when calling BASS_ChannelGetData. Terminating decoding: " + error.ToString());
break;
}
if (bytesRead > 0)
{
ms = new MemoryStream(bytesRead);
ms.Write(buf, 0, bytesRead);
if (DecodedDataReady != null)
DecodedDataReady(ms.ToArray(), (int)decodingStream.PositionInPercent);
}
}
Bass.BASS_StreamFree(mixHandle);
Bass.BASS_StreamFree(encodeHandle);
Is it because it does not use the 16000 parameter in BASS_Mixer_StreamCreate?
If i use an 44100Hz mono as input audio to the mixer, it puts out the correct 16kHz mono.
Any ideas?

3delite

  • Posts: 907
Re: mixing to 16kHz mono but get 96kHz mono
« Reply #1 on: 2 Nov '17 - 11:55 »
Use 'mixHandle' is the calls, like BassEnc.BASS_Encode_Start(mixHandle, ...), etc.

jakob

  • Posts: 105
Re: mixing to 16kHz mono but get 96kHz mono
« Reply #2 on: 2 Nov '17 - 14:07 »
Thank you  :D. i should have seen that myself

3delite

  • Posts: 907
Re: mixing to 16kHz mono but get 96kHz mono
« Reply #3 on: 2 Nov '17 - 18:54 »
Ok then. :)