20 Jun '13 - 07:44 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: Join two mp3 files  (Read 472 times)
The_searcher
Guest
« on: 3 Jun '12 - 17:36 »
Reply with quoteQuote

Hello,
I try to do:
1. Open first mp3 file to stream. (work)
2. Then  open second mp3 file and push it to first's file stream. (fail)
3. Play channel made of two files. (work, but plays only first file)

Is it possible to join two mp3 files in one channel using BASS_StreamPutData?

// DWORD chan; // channel which I operate on hidden in class

void MainWindow::play()
{
    BASS_ChannelPlay(chan, false);
}

void MainWindow::load_first()
{
    QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "C:\\",tr("Music (*.mp3)"));
    char* c_fileName = NULL;
    if(fileName.isEmpty()) return;

    c_fileName = new char[fileName.size()+1];
    strcpy(c_fileName, fileName.toStdString().c_str());

    if(!(chan = BASS_StreamCreateFile(false, c_fileName, 0, 0, 0))) {
        QMessageBox::critical(this, "Blad", "Nie udalo sie odtworzyc pliku!");
        exit(1);
    }

    delete[] c_fileName;
}

void MainWindow::load_second()
{
    QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "C:\\",tr("Music (*.mp3)"));
    char* c_fileName = NULL;
    if(fileName.isEmpty()) return;

    c_fileName = new char[fileName.size()+1];
    strcpy(c_fileName, fileName.toStdString().c_str());
    // push data to stream!
    BASS_StreamPutData(chan, 0, 0);


    delete[] c_fileName;
}
Logged
fmcoder
Posts: 387


« Reply #1 on: 4 Jun '12 - 11:08 »
Reply with quoteQuote

You should use the BASSmix addon if you want to mix 2 files together.
Logged
Ian @ un4seen
Administrator
Posts: 15366


« Reply #2 on: 4 Jun '12 - 16:49 »
Reply with quoteQuote

Is it possible to join two mp3 files in one channel using BASS_StreamPutData?

Yes, but you would need to create a "push" stream for it (using BASS_StreamCreate), and you could then feed the data from both files into that (using BASS_StreamPutData). Pre-decoding data from the files may not be the most effecient way to do it though. Another way to do it is to use a STREAMPROC callback function, which can decode data from the files as it's needed. Something like this...

#define sources 2
HSTREAM source[sources];
int currentsource;

...

source[0]=BASS_StreamCreateFile(FALSE, filename[0], 0, 0, BASS_STREAM_DECODE); // create "decoding channel" for 1st file
source[1]=BASS_StreamCreateFile(FALSE, filename[1], 0, 0, BASS_STREAM_DECODE); // and the 2nd file

BASS_CHANNELINO ci;
BASS_ChannelGetInfo(source[0], &ci); // get sample format info
output=BASS_StreamCreate(ci.freq, ci.chans, 0, StreamProc, 0); // create a custom stream with same format
currentsource=0;
BASS_ChannelPlay(output, 0); // start it

...

DWORD CALLBACK StreamProc(HSTREAM handle, void *buf, DWORD len, void *user)
{
retry:
DWORD r=BASS_ChannelGetData(source[currentsource], buf, len); // get data from the current sound
if (r==(DWORD)-1) { // failed
if (currentsource==sources-1) return BASS_STREAMPROC_END; // reached the end
currentsource++; // advance to next source
goto retry;
}
return r;
}

Note the source files need to have an identical sample format (sample rate and channel count) for this to work properly. If they don't, you could use the BASSmix add-on instead, which can resample them to a common format. Here's a thread on that...

   www.un4seen.com/forum/?topic=6159
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines