2

Im using BASS.dll library and all I want to do is to "redirect" part of MP3 Im playing using for example BASS_StreamCreateFile to another file (may be MP3 or WAVe). I dont know how to start? Im trying to use help to find an answer, but still nothing. I can play this stream. Read some data I need. Now I need to copy ile for example from 2:00 to 2:10 (or by position). Any ideas how should I start?

Regards, J.K.

Jakub Krol
  • 350
  • 5
  • 16
  • 1
    1) Seek to the correct position. 2) Copy the data into a buffer. 3) Create an output file. 4) Copy the buffer into the output file. Which part(s) are you having trouble with? – Mason Wheeler Nov 15 '11 at 13:26
  • I dont want to hard-copy part of file. I want to copy part of MP3 into another MP3. I cannot just copy for example X bytes. – Jakub Krol Nov 15 '11 at 14:23

1 Answers1

3

Well, I don't know BASS specifically, but I know a little about music playing and compressed data formats in general, and copying the data around properly involves an intermediate decoding step. Here's what you'll need to do:

  1. Open the file and find the correct position.
  2. Decode the audio into an in-memory buffer. The size of your buffer should be (LengthInSeconds * SamplesPerSecond * Channels * BytesPerSample) bytes. So if it's 10 seconds of CD quality audio, that's 10 * 44100 * 2 (stereo) * 2 (16-bit audio) = 1764000 bytes.
  3. Take this buffer of decoded data and feed it into an MP3 encoding function, and save the resulting MP3 to a file.

If BASS has functions for decoding to an external buffer and for encoding a buffer to MP3, you're good; all you have to do is figure out which ones to use. If not, you'll have to find another library for MP3 encoding and decoding.

Also, watch out for generational loss. MP3 uses lossy compression, so if you decompress and recompress the data multiple times, it'll hurt the sound quality.

Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477
  • Thats a good point, thanks. Ill try it and Ill also try to find another library for this. And Ill let you know - if it works Ill accept this answer. – Jakub Krol Nov 16 '11 at 10:55