Question

We're writing a flash application that can download a MP3 file, convert it to a Sound object, get the raw data and make some processing (like adding sounds, change octaves). After the processing, we want to send the data back to the server in chunks, so the server will be able to glue the data together and recover the new generated file. The problem is: if we send to the server "wav" pieces of sound, we are able to glue them together without any problem in the generated file. However, if we convert each wav piece to a mp3 file (so we can send a smaller file to the server) and join the mp3 files at the server, the result is a sound with some problems at the merge point.

This is how we load the mp3 file from the server:

sourceSnd.load(new URLRequest("sample url to mp3"));
sourceSnd.addEventListener(Event.COMPLETE, carregou);

This is how we convert each piece of mp3 to bytearray and wav:

sourceSnd.extract(buffer, tamanho2);        
...process the extract sound and....
var bytesWav : ByteArray = new ByteArray();
buffer.position = 0;
this.wavWriter.processSamples(bytesWav, buffer, 44100, 2);

If we send each mini-wav file back to the server (for example, using a socket), we are able to glue them together without any problems. However, if we convert each wav bytearray using this code:

bytesWav.position = 0;
var mp3Encoder : ShineMP3Encoder = new ShineMP3Encoder(bytesWav);
var objeto : teste = this;                                  
mp3Encoder.addEventListener(Event.COMPLETE, function(event : Event) : void {
    objeto.socket.send(mp3Encoder.mp3Data);
});
mp3Encoder.start();

after joining the files, the mp3 file created has many sound problems at the "merge" points.

How can we avoid such sound problems?

Client-side technology: AS3 Server-side techonology: grails

Was it helpful?

Solution

Turns outs this was caused by the process of enconding each piece of the wav to mp3. The encoder was converting them to whole mp3 files, adding silence to the first and the last frames of each piece. You can see the detailed explanation here: http://lame.sourceforge.net/tech-FAQ.txt

To solve this problem, we had to edit the ShineMP3Encoder source code so it wouldn't add the start and end frames for each piece processed (turning it in a "chunk processor"). This solved the problem and we were able to stream the modified mp3 file from the client to the server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top