May I ask an audio encoding question

Started by one808,

one808

May I ask, how do I process the audio file data into 48K sampling rate, 32-bit floating-point, and monaural data? Then, I extract the data (frame_1en=480 * sizeof (float)) using BASS-Channel Data (mixer48k, buf, frame_1en) and process the buf data using DSP_decess() to obtain a new [new-buf]. I want to resample this [new-buf] data to obtain a new 16K/8K sampling rate, 16 bit, and monaural data?

Ian @ un4seen

Quote from: one808May I ask, how do I process the audio file data into 48K sampling rate, 32-bit floating-point, and monaural data? Then, I extract the data (frame_1en=480 * sizeof (float)) using BASS-Channel Data (mixer48k, buf, frame_1en) and process the buf data...

Is the audio file already 48KHz mono, or do you want to convert it to that? If you want to convert it then you can use the BASSmix add-on to do that, something like this:

mixer = BASS_Mixer_StreamCreate(48000, 1, BASS_MIXER_END | BASS_SAMPLE_FLOAT | BASS_STREAM_DECODE); // create floating-point 48KHz mono mixer
BASS_Mixer_StreamAddChannel(mixer, decoder, BASS_MIXER_CHAN_DOWNMIX | BASS_MIXER_CHAN_NORAMPIN); // add file decoder to mixer with downmixing
for (;;) {
    float buf[480];
    int got = BASS_ChannelData(mixer, buf, sizeof(buf)); // get data from mixer
    if (got <= 0) break; // ended
    // process buf data here...
}

Please see the BASS_Mixer_StreamCreate and BASS_Mixer_StreamAddChannel documentation for details.

one808

Quote from: Ian @ un4seen
Quote from: one808May I ask, how do I process the audio file data into 48K sampling rate, 32-bit floating-point, and monaural data? Then, I extract the data (frame_1en=480 * sizeof (float)) using BASS-Channel Data (mixer48k, buf, frame_1en) and process the buf data...

Is the audio file already 48KHz mono, or do you want to convert it to that? If you want to convert it then you can use the BASSmix add-on to do that, something like this:

mixer = BASS_Mixer_StreamCreate(48000, 1, BASS_MIXER_END | BASS_SAMPLE_FLOAT | BASS_STREAM_DECODE); // create floating-point 48KHz mono mixer
BASS_Mixer_StreamAddChannel(mixer, decoder, BASS_MIXER_CHAN_DOWNMIX | BASS_MIXER_CHAN_NORAMPIN); // add file decoder to mixer with downmixing
for (;;) {
    float buf[480];
    int got = BASS_ChannelData(mixer, buf, sizeof(buf)); // get data from mixer
    if (got <= 0) break; // ended
    // process buf data here...
}

Please see the BASS_Mixer_StreamCreate and BASS_Mixer_StreamAddChannel documentation for details.

Thank you [Ian @ un4seen] for your reply. I have already retrieved the buf data for [mixer], but I need to process [mixer buf data (freq: 48k, 32-bit float, mono)] ->[noise DSP process] ->[new buf data (freq: 48k, 32-bit float, mono)] ->[processed data (freq: 16k, 16 bit, mono)] ->save pcm file

Ian @ un4seen

Quote from: one808I need to process [mixer buf data (freq: 48k, 32-bit float, mono)] ->[noise DSP process] ->[new buf data (freq: 48k, 32-bit float, mono)]

That looks like you could apply the "noise DSP process" directly on the data in "buf" with no need for another buffer? But if the processing does need a separate output buffer then you can allocate one, eg. named "buf2" or "bufout".

Quote from: one808[new buf data (freq: 48k, 32-bit float, mono)] ->[processed data (freq: 16k, 16 bit, mono)] ->save pcm file

You can use another mixer to convert to 16KHz, and the BASSenc add-on to write the file. You can use a "push" stream to feed your processed data to this mixer. The previous code could be updated something like this:

mixer = BASS_Mixer_StreamCreate(48000, 1, BASS_MIXER_END | BASS_SAMPLE_FLOAT | BASS_STREAM_DECODE); // create floating-point 48KHz mono mixer
BASS_Mixer_StreamAddChannel(mixer, decoder, BASS_MIXER_CHAN_DOWNMIX | BASS_MIXER_CHAN_NORAMPIN); // add file decoder to mixer with downmixing
stream2 = BASS_StreamCreate(48000, 1, BASS_SAMPLE_FLOAT | BASS_STREAM_DECODE, STREAMPROC_PUSH, 0); // create floating-point 48KHz mono push stream
mixer2 = BASS_Mixer_StreamCreate(16000, 1, BASS_MIXER_END | BASS_STREAM_DECODE); // create 16-bit 16KHz mono mixer
BASS_Mixer_StreamAddChannel(mixer2, stream2, BASS_MIXER_CHAN_NORAMPIN); // add push stream to mixer
BASS_Encode_Start(mixer2, "output.wav", BASS_ENCODE_PCM | BASS_ENCODE_AUTOFREE, 0, 0); // set WAV writer on mixer

for (;;) {
    float buf[480];
    int got = BASS_ChannelData(mixer, buf, sizeof(buf)); // get data from 1st mixer
    if (got <= 0) break; // ended
    // process buf data here
    BASS_StreamPutData(stream2, buf, got); // send processed data to push stream
    BASS_ChannelData(mixer2, buf, sizeof(buf)); // process 2nd mixer (inc. WAV writing)
}

BASS_StreamFree(mixer);
BASS_StreamFree(mixer2);
BASS_StreamFree(stream2);

one808

Quote from: Ian @ un4seen
Quote from: one808I need to process [mixer buf data (freq: 48k, 32-bit float, mono)] ->[noise DSP process] ->[new buf data (freq: 48k, 32-bit float, mono)]

That looks like you could apply the "noise DSP process" directly on the data in "buf" with no need for another buffer? But if the processing does need a separate output buffer then you can allocate one, eg. named "buf2" or "bufout".

Quote from: one808[new buf data (freq: 48k, 32-bit float, mono)] ->[processed data (freq: 16k, 16 bit, mono)] ->save pcm file

You can use another mixer to convert to 16KHz, and the BASSenc add-on to write the file. You can use a "push" stream to feed your processed data to this mixer. The previous code could be updated something like this:

mixer = BASS_Mixer_StreamCreate(48000, 1, BASS_MIXER_END | BASS_SAMPLE_FLOAT | BASS_STREAM_DECODE); // create floating-point 48KHz mono mixer
BASS_Mixer_StreamAddChannel(mixer, decoder, BASS_MIXER_CHAN_DOWNMIX | BASS_MIXER_CHAN_NORAMPIN); // add file decoder to mixer with downmixing
stream2 = BASS_StreamCreate(48000, 1, BASS_SAMPLE_FLOAT | BASS_STREAM_DECODE, STREAMPROC_PUSH, 0); // create floating-point 48KHz mono push stream
mixer2 = BASS_Mixer_StreamCreate(16000, 1, BASS_MIXER_END | BASS_STREAM_DECODE); // create 16-bit 16KHz mono mixer
BASS_Mixer_StreamAddChannel(mixer2, stream2, BASS_MIXER_CHAN_NORAMPIN); // add push stream to mixer
BASS_Encode_Start(mixer2, "output.wav", BASS_ENCODE_PCM | BASS_ENCODE_AUTOFREE, 0, 0); // set WAV writer on mixer

for (;;) {
    float buf[480];
    int got = BASS_ChannelData(mixer, buf, sizeof(buf)); // get data from 1st mixer
    if (got <= 0) break; // ended
    // process buf data here
    BASS_StreamPutData(stream2, buf, got); // send processed data to push stream
    BASS_ChannelData(mixer2, buf, sizeof(buf)); // process 2nd mixer (inc. WAV writing)
}

BASS_StreamFree(mixer);
BASS_StreamFree(mixer2);
BASS_StreamFree(stream2);


Thank you very much for the help from Ian @ un4seen