Discussion:
[mad-user] dual-thread libmad
Steve Spano
2007-12-07 13:07:05 UTC
Permalink
I have made a lot of progress working with libmad and trying to get two
instances running.



I have a simple RTOS which has two threads. Each thread starts lib mad
with a dedicated mad_decoder buffer for each thread. I am now able to
"read" data correcting into the decoders (i.e. I don't see decoding
errors streaming everywhere on the debug trace) but the output audio is
mixed up. Meaning that the audio from the two threads is being mixed
(actually shuffled) during playback.



Seems like there may be another global buffer being used somewhere that
I have to split out onto two threads or something. Can anyone help with
ideas on how to have two threads, play two different MP3s, using libmad?



Thanks



Steve Spano, President

Finger Lakes Engineering
john cooper
2007-12-07 15:09:24 UTC
Permalink
Post by Steve Spano
I have a simple RTOS which has two threads. Each thread starts lib mad
with a dedicated mad_decoder buffer for each thread. I am now able to
“read” data correcting into the decoders (i.e. I don’t see decoding
errors streaming everywhere on the debug trace) but the output audio is
mixed up. Meaning that the audio from the two threads is being mixed
(actually shuffled) during playback.
It is built into the API. You'll need to keep separate
frame/stream/synth data structures for each instance of
a decode operation. Sounds like you are rendering to the
same set of structures multiplexed by the task scheduler.

-john
--
***@third-harmonic.com
Steve Spano
2007-12-08 03:23:23 UTC
Permalink
Hi John,

Thanks for the reply.

I did more tracking into this, the mad_decoder_buffer creates the
instances on the frame/stream/sync data. I already created two instances
of the mad_decoder_buffer so I could link them to each RTOS thread.

It looks like the samples are getting mixed up at the output stage. It
turns out that one of the MP3s playing is a 1-channel and the other MP3
is a 2-channel. Any thoughts perhaps on how mixing of sample data,
between RTOS tasks, could occur on the output stages?

I figured this part out, that it is occurring at the output stage,
Friday ~ 5pm. I have to look at it some more.

Thanks

Steve Spano, President
Finger Lakes Engineering


-----Original Message-----
From: john cooper [mailto:***@third-harmonic.com]
Sent: Friday, December 07, 2007 10:09 AM
To: Steve Spano
Cc: mad-***@lists.mars.org; john cooper
Subject: Re: [mad-user] dual-thread libmad
Post by Steve Spano
I have a simple RTOS which has two threads. Each thread starts lib mad
with a dedicated mad_decoder buffer for each thread. I am now able to
"read" data correcting into the decoders (i.e. I don't see decoding
errors streaming everywhere on the debug trace) but the output audio
is
Post by Steve Spano
mixed up. Meaning that the audio from the two threads is being mixed
(actually shuffled) during playback.
It is built into the API. You'll need to keep separate
frame/stream/synth data structures for each instance of
a decode operation. Sounds like you are rendering to the
same set of structures multiplexed by the task scheduler.

-john
--
***@third-harmonic.com
john cooper
2007-12-08 14:04:13 UTC
Permalink
Post by Steve Spano
Hi John,
Thanks for the reply.
I did more tracking into this, the mad_decoder_buffer creates the
instances on the frame/stream/sync data. I already created two instances
of the mad_decoder_buffer so I could link them to each RTOS thread.
It looks like the samples are getting mixed up at the output stage. It
turns out that one of the MP3s playing is a 1-channel and the other MP3
is a 2-channel. Any thoughts perhaps on how mixing of sample data,
between RTOS tasks, could occur on the output stages?
You'll need to make output the data rates agree potentially
converting one to the other. And you will need to
synchronize and mix the two streams before they hit the
audio device. This should be relatively straightforward
but you may need to scale the data to avoid clipping during
the mix operation.

-john
Post by Steve Spano
I figured this part out, that it is occurring at the output stage,
Friday ~ 5pm. I have to look at it some more.
Thanks
Steve Spano, President
Finger Lakes Engineering
-----Original Message-----
Sent: Friday, December 07, 2007 10:09 AM
To: Steve Spano
Subject: Re: [mad-user] dual-thread libmad
Post by Steve Spano
I have a simple RTOS which has two threads. Each thread starts lib mad
with a dedicated mad_decoder buffer for each thread. I am now able to
"read" data correcting into the decoders (i.e. I don't see decoding
errors streaming everywhere on the debug trace) but the output audio
is
Post by Steve Spano
mixed up. Meaning that the audio from the two threads is being mixed
(actually shuffled) during playback.
It is built into the API. You'll need to keep separate
frame/stream/synth data structures for each instance of
a decode operation. Sounds like you are rendering to the
same set of structures multiplexed by the task scheduler.
-john
--
***@third-harmonic.com
Steve Spano
2007-12-09 00:12:52 UTC
Permalink
Hi John

Thanks for the reply.

I actually don't want any mixing at all. I want MP3(A) to be played on
channel A and MP3(B) to be played on channel B. Something is occurring,
which appears to be towards the output stage of my libmad, that is
causing the A and B samples to mix together. So I am looking for some
global buffer that is being using by both A and B or something like that
which the RTOS is mixing between both threads.

Steve Spano, President
Finger Lakes Engineering


-----Original Message-----
From: john cooper [mailto:***@third-harmonic.com]
Sent: Saturday, December 08, 2007 9:04 AM
To: Steve Spano
Cc: mad-***@lists.mars.org
Subject: Re: [mad-user] dual-thread libmad
Post by Steve Spano
Hi John,
Thanks for the reply.
I did more tracking into this, the mad_decoder_buffer creates the
instances on the frame/stream/sync data. I already created two
instances
Post by Steve Spano
of the mad_decoder_buffer so I could link them to each RTOS thread.
It looks like the samples are getting mixed up at the output stage. It
turns out that one of the MP3s playing is a 1-channel and the other
MP3
Post by Steve Spano
is a 2-channel. Any thoughts perhaps on how mixing of sample data,
between RTOS tasks, could occur on the output stages?
You'll need to make output the data rates agree potentially
converting one to the other. And you will need to
synchronize and mix the two streams before they hit the
audio device. This should be relatively straightforward
but you may need to scale the data to avoid clipping during
the mix operation.

-john
Post by Steve Spano
I figured this part out, that it is occurring at the output stage,
Friday ~ 5pm. I have to look at it some more.
Thanks
Steve Spano, President
Finger Lakes Engineering
-----Original Message-----
Sent: Friday, December 07, 2007 10:09 AM
To: Steve Spano
Subject: Re: [mad-user] dual-thread libmad
Post by Steve Spano
I have a simple RTOS which has two threads. Each thread starts lib
mad
Post by Steve Spano
Post by Steve Spano
with a dedicated mad_decoder buffer for each thread. I am now able to
"read" data correcting into the decoders (i.e. I don't see decoding
errors streaming everywhere on the debug trace) but the output audio
is
Post by Steve Spano
mixed up. Meaning that the audio from the two threads is being mixed
(actually shuffled) during playback.
It is built into the API. You'll need to keep separate
frame/stream/synth data structures for each instance of
a decode operation. Sounds like you are rendering to the
same set of structures multiplexed by the task scheduler.
-john
--
***@third-harmonic.com
Loading...