Author Topic: Apply Channel attribute to sample data (decode channel)  (Read 72 times)

Nikuro

  • Posts: 2
There is my code:
Code: [Select]
HSTREAM channel = BASS_StreamCreateFile(false, "test.mp3", 0, 0, BASS_STREAM_DECODE);

BASS_Encode_Start(channel, "output.wav", BASS_ENCODE_PCM, NULL, NULL);

float sampleRate;
BASS_ChannelGetAttribute(channel, BASS_ATTRIB_FREQ, &sampleRate);
BASS_ChannelSetAttribute(channel, BASS_ATTRIB_FREQ, sampleRate * 0.85);

while (!kbhit()) {
    BYTE buf[20000]; // processing buffer
    int r = BASS_ChannelGetData(channel, buf, sizeof(buf));

    if (r == -1) break; // done
}

BASS_Encode_Stop(channel);

I read in documentation (http://www.un4seen.com/doc/#bass/BASS_ATTRIB_FREQ.html) and its say:
Quote
This attribute applies to playback of the channel, and does not affect the channel's sample data, so it has no real effect on decoding channels. It is still adjustable then though, so that it can be used by the BASSmix add-on and anything else that wants to use it.

Is there a way to apply that attribute (and others also) to sample data or encoder?

Ian @ un4seen

  • Administrator
  • Posts: 23743
The BASSmix add-on will apply the BASS_ATTRIB_FREQ setting (BASS_ATTRIB_VOL/PAN too) of its source channels, so that can be used to get the result of them being applied, eg. set the WAV writer on the mixer to save the mixer output. For resampling purposes, you don't actually need to change the source's BASS_ATTRIB_FREQ setting but rather just create a mixer with the new rate. For example, your code could be modified like this:

Code: [Select]
HSTREAM channel = BASS_StreamCreateFile(false, "test.mp3", 0, 0, BASS_STREAM_DECODE);

BASS_CHANNELINFO info;
BASS_ChannelGetInfo(channel, &info); // get the channel's info
HSTREAM mixer = BASS_Mixer_StreamCreate(info.freq * 0.85, info.chans, BASS_MIXER_END | BASS_STREAM_DECODE); // create a mixer with the wanted rate
BASS_Mixer_StreamAddChannel(mixer, channel, BASS_MIXER_CHAN_NORAMPIN); // plug the source channel into it

BASS_Encode_Start(mixer, "output.wav", BASS_ENCODE_PCM, NULL, NULL);

while (!kbhit()) {
    BYTE buf[20000]; // processing buffer
    int r = BASS_ChannelGetData(mixer, buf, sizeof(buf));

    if (r == -1) break; // done
}

BASS_Encode_Stop(mixer);
BASS_StreamFree(mixer);

Please see the BASSmix documentation for details on the mentioned functions.