Author Topic: Modify song parameters and save to file  (Read 1705 times)

pfamircea

  • Posts: 20
Modify song parameters and save to file
« on: 11 Mar '15 - 12:55 »
I *think* I need encoders for this, but I want a confirmation and some pointers.

I want to modify some song parameters, volume, pitch, etc to any kind of supported playback file, then save that to file.
This for mp3, midi, kar, etc.
Do I need to use bassenc and appropriate encoders or is there some other way?
If it's bassenc, where do I find the various encoders for this? I only see lame and ogg on the download page.

Thanks.

Ian @ un4seen

  • Administrator
  • Posts: 20389
Re: Modify song parameters and save to file
« Reply #1 on: 11 Mar '15 - 17:27 »
Do you want to write the new file in the same format as the old file? That won't be possible with formats like MIDI. It will probably be best to just stick with a few common output format options, eg. WAV/MP3/OGG/FLAC. You can indeed use the BASSenc add-on and appropriate encoders to write the files. The FLAC encoder can be found here:

   http://downloads.xiph.org/releases/flac/flac-1.3.1-win.zip

pfamircea

  • Posts: 20
Re: Modify song parameters and save to file
« Reply #2 on: 11 Mar '15 - 17:53 »
I was afraid of that.
Ok, so I'll go with a "system limitation" on this :)

Thank you.

pfamircea

  • Posts: 20
Re: Modify song parameters and save to file
« Reply #3 on: 19 Mar '15 - 14:09 »
I think I may be doing something wrong.

I tested the following:
- 1 midi file as input
- mp3 file as output
- changed tempo then played file. It played with expected results. Saved via mp3 encoder, it did not seem affected
- same happened for pitch and volume. I read the docs and volume says decoding channels are not affected, but was not able to find another way to actually do it.

The code flows like this (for saving):
- channel := BASS_StreamCreateFile(false, filename, 0, 0, BASS_STEAM_DECODE or BASS_STREAM_UNICODE); | playback has an extra BASS_SAMPLE_FLOAT
- channel_fx := BASS_FX_TempotCreate(channel, BASS_FX_FREESOURCE or BASS_SAMPLE_FLOAT);
- BASS_ChannelSetDSP(channel_fx, proc, nil, 0); (the procedure just calls BASS_StreamPutData(0, buffer, length)
- BASS_ChannelSetAttribute(channel_fx, BASS_ATTRIB_TEMPO_PITCH, x); x between -60 and 60
- BASS_Encode_Start(channel, cmd, BASS_ENCODE_FP_16BIT or BASS_ENCODE_AUTOFREE or BASS_UNICODE, nil, nil);
  cmd is lame.exe --alt-reset standard - "outputfile.mp3"
- then, in a loop: BASS_ChannerlGetData(channel, buffer, size);

Any pointers?

Thanks.

Ian @ un4seen

  • Administrator
  • Posts: 20389
Re: Modify song parameters and save to file
« Reply #4 on: 19 Mar '15 - 14:49 »
The encoder should be set on the "channel_fx" tempo stream in the BASS_Encode_Start call, so that it receives the tempo processing output. If the encoder is set on the "channel" decoder (as above), it will receive the original unprocessed data.

pfamircea

  • Posts: 20
Re: Modify song parameters and save to file
« Reply #5 on: 19 Mar '15 - 15:18 »
That makes sense. I did try that before, but I also passed the fx handle to the channelGetData but then it was returning 0 continuously for some reason.

also, having encode_start with (fx-handle) and channelGetData with non-fx-handle, the loop processes, but also no file is being created.

here are my results (encode_start, channelGetData):
- non-fx, non-fx => file created, output not modified
- non-fx, fx => channelGetData returns 0 all the time
- fx, fx => channelGetData returns 0 all the time
- fx, non-fx => no file created

so I guess there is something more to it.

Thanks.

Ian @ un4seen

  • Administrator
  • Posts: 20389
Re: Modify song parameters and save to file
« Reply #6 on: 19 Mar '15 - 16:35 »
That makes sense. I did try that before, but I also passed the fx handle to the channelGetData but then it was returning 0 continuously for some reason.

Make sure you include the BASS_STREAM_DECODE flag in the BASS_FX_TempoCreate call to make the tempo stream a "decoding channel", which allows you to process it via BASS_ChannelGetData. You can also remove the BASS_SAMPLE_FLOAT flag from that call, as it will be having no effect; a tempo stream will always have the same sample format as its source.

pfamircea

  • Posts: 20
Re: Modify song parameters and save to file
« Reply #7 on: 19 Mar '15 - 16:48 »
hah, that was a logical thing to do :) Thanks.

What about volume? Any chance I can get that modified in the encoded output?

Ian @ un4seen

  • Administrator
  • Posts: 20389
Re: Modify song parameters and save to file
« Reply #8 on: 19 Mar '15 - 17:09 »
The usual BASS_ATTRIB_VOL volume control option won't have any effect in this case, but you can use the BASS_FX add-on's BASS_FX_BFX_VOLUME effect instead. Something like this...

Code: [Select]
volfx=BASS_ChannelSetFX(channel_fx, BASS_FX_BFX_VOLUME, 0);
BASS_BFX_VOLUME volparam={0, volume);
BASS_FXSetParameters(volfx, &volparam);

pfamircea

  • Posts: 20
Re: Modify song parameters and save to file
« Reply #9 on: 19 Mar '15 - 19:18 »
That worked as expected. Thank you very much.

pfamircea

  • Posts: 20
Re: Modify song parameters and save to file
« Reply #10 on: 8 Jul '15 - 17:26 »
Different issue, but on the same topic and test scenario:

1 midi in, mp3 out, generally, the flow goes as instructed earlier. Volume, pitch, tempo work fine.

I'm trying to implement midi channel volume control. Playback goes fine when I issue BASS_MIDI_StreamEvent(regular handle, MIDI_EVENT_VOLUME), however the same call, done before (and after - for testing purposes) of calling BASS_Encode_Start(fxhandle) has no effect in the output (mp3)

So how would I go about inserting midi event (specifically the volume control) before BASS_ChannelGetData call so that it has effect in the output mp3?

Thanks.

Ian @ un4seen

  • Administrator
  • Posts: 20389
Re: Modify song parameters and save to file
« Reply #11 on: 8 Jul '15 - 17:34 »
I would recommend using the MIDI_EVENT_MIXLEVEL event instead of MIDI_EVENT_VOLUME, as the latter can be overridden by the MIDI file, ie. the file may have its own MIDI_EVENT_VOLUME events. MIDI_EVENT_MIXLEVEL can't be overridden by the MIDI file.

pfamircea

  • Posts: 20
Re: Modify song parameters and save to file
« Reply #12 on: 8 Jul '15 - 17:52 »
That worked :) Weird for me, as I expected the same result for playing and for saving.

Thanks