Smpeg and SDL_Mixer

Hello all,
I have been trying to use smpeg and SDL_Mixer together and have had
very little luck. I was wondering if anyone has any tips. If I open
the mixer any audio output from my smpeg goes very slowly. If I do not
open the mixer and just use smpeg the audio plays fine. Am I doing
something incorrectly. plaympeg says the audio is “Audio MPEG-1 Layer 2
224kbit/s 44100Hz stereo”. I set my MIX_OpenAudio to:

if(Mix_OpenAudio(441000, MIX_DEFAULT_FORMAT, 2, 1024)

and it goes really slowly. Now, does MIX just take up that much extra
processing, or doesn’t it play well with mixer, or do I have a setting
wrong?

My guess, is that both smpeg and Mix are trying to service the same
resource, the sound buffer, and at double the processing, we have double
the cost. I am hoping this assumption is wrong and that I just have a
Mixer setting wrong, and that I don’t have to design my own.

Robert

This is a common problem. Basically, the problem is that SMPEG syncs
the video with the audio, which means that SMPEG needs to know how fast
the audio is consumed. Otherwise, SMPEG tries to sync with the audio
cursor, which it can’t see… so you get something in the 1 frame per
second range…

The solution is two fold:

  1. When you load the MPEG movie, you need to make sure the sdl_audio
    flag is ZERO!!!.. When this value is non-zero, SMPEG tries to play the
    audio DIRECTLY through SDL… If you’re using SDL_mixer, you need to
    play through SDL_mixer instead…

  2. You need to cross hook the SMPEG output to the SDL_mixer input…

Check out smpeg/README.SDL_mixer for details…

-LorenOn Mon, 2002-12-16 at 17:13, Robert Diel wrote:

Hello all,
I have been trying to use smpeg and SDL_Mixer together and have had
very little luck. I was wondering if anyone has any tips. If I open
the mixer any audio output from my smpeg goes very slowly. If I do not
open the mixer and just use smpeg the audio plays fine. Am I doing
something incorrectly. plaympeg says the audio is “Audio MPEG-1 Layer 2
224kbit/s 44100Hz stereo”. I set my MIX_OpenAudio to:

if(Mix_OpenAudio(441000, MIX_DEFAULT_FORMAT, 2, 1024)

and it goes really slowly. Now, does MIX just take up that much extra
processing, or doesn’t it play well with mixer, or do I have a setting
wrong?

My guess, is that both smpeg and Mix are trying to service the same
resource, the sound buffer, and at double the processing, we have double
the cost. I am hoping this assumption is wrong and that I just have a
Mixer setting wrong, and that I don’t have to design my own.

Robert


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I tried this method and it definitely works better, but it’s a bit slow,
and has a really really weird echo. It sounds like it’s being played by
smpeg and then shadowed by the mixer. Any ideas? I directly stole the
code from the README.SDL_Mixer in the SMPEG directory. I am running
SMPEG 0.4.4, if this helps at all.

Here’s the code:

 .... SDL INIT STUFF...

 /* Open the audio device */
 if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024)==-1){
          fprintf(stderr,
	        "Warning: Couldn't set 11025 Hz 8-bit audio\n- Reason:

%s\n", SDL_GetError());
use_audio=0;
}

SMPEG *mpeg;
SMPEG_Info info;
int volume = 100;

SDL_Delay(1000);
/* Create the MPEG stream */
mpeg = SMPEG_new("letsroll.mpg", &info, use_audio);
if ( SMPEG_error(mpeg) ) {
fprintf(stderr, "%s: %s\n", "letsroll.mpg",         

SMPEG_error(mpeg));
SMPEG_delete(mpeg);
}
SMPEG_enablevideo(mpeg, use_video);
SMPEG_enableaudio(mpeg, 0);
if ( use_audio ) {
SDL_AudioSpec audiofmt;
Uint16 format;
int freq, channels;

            /* Tell SMPEG what the audio format is */
            Mix_QuerySpec(&freq, &format, &channels);
            audiofmt.format = format;
            audiofmt.freq = freq;
            audiofmt.channels = channels;
            SMPEG_actualSpec(mpeg, &audiofmt);

            /* Hook in the MPEG music mixer */
            Mix_HookMusic(myMusicPlayer , mpeg);
            SMPEG_enableaudio(mpeg, 1);
}
SMPEG_setvolume(mpeg, volume);
SMPEG_play(mpeg);

}

//…Linking Directly to SMPEG_playAudio didn’t work so well…
void myMusicPlayer(void *udata, Uint8 stream, int len)
{
SMPEG_playAudio((SMPEG
)udata,stream,len);
}

Any suggestions would be helpful.

RobertOn Mon, 2002-12-16 at 21:30, Loren Osborn wrote:

This is a common problem. Basically, the problem is that SMPEG syncs
the video with the audio, which means that SMPEG needs to know how fast
the audio is consumed. Otherwise, SMPEG tries to sync with the audio
cursor, which it can’t see… so you get something in the 1 frame per
second range…

The solution is two fold:

  1. When you load the MPEG movie, you need to make sure the sdl_audio
    flag is ZERO!!!.. When this value is non-zero, SMPEG tries to play the
    audio DIRECTLY through SDL… If you’re using SDL_mixer, you need to
    play through SDL_mixer instead…

  2. You need to cross hook the SMPEG output to the SDL_mixer input…

Check out smpeg/README.SDL_mixer for details…

-Loren

On Mon, 2002-12-16 at 17:13, Robert Diel wrote:

Hello all,
I have been trying to use smpeg and SDL_Mixer together and have had
very little luck. I was wondering if anyone has any tips. If I open
the mixer any audio output from my smpeg goes very slowly. If I do not
open the mixer and just use smpeg the audio plays fine. Am I doing
something incorrectly. plaympeg says the audio is “Audio MPEG-1 Layer 2
224kbit/s 44100Hz stereo”. I set my MIX_OpenAudio to:

if(Mix_OpenAudio(441000, MIX_DEFAULT_FORMAT, 2, 1024)

and it goes really slowly. Now, does MIX just take up that much extra
processing, or doesn’t it play well with mixer, or do I have a setting
wrong?

My guess, is that both smpeg and Mix are trying to service the same
resource, the sound buffer, and at double the processing, we have double
the cost. I am hoping this assumption is wrong and that I just have a
Mixer setting wrong, and that I don’t have to design my own.

Robert


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Found it, I’m really dumb. It was the fact that you initialize the
audio when you new up the mpeg, which when you set that to zero, no
problems.

Thank you for the help,
RobertOn Mon, 2002-12-16 at 21:30, Loren Osborn wrote:

This is a common problem. Basically, the problem is that SMPEG syncs
the video with the audio, which means that SMPEG needs to know how fast
the audio is consumed. Otherwise, SMPEG tries to sync with the audio
cursor, which it can’t see… so you get something in the 1 frame per
second range…

The solution is two fold:

  1. When you load the MPEG movie, you need to make sure the sdl_audio
    flag is ZERO!!!.. When this value is non-zero, SMPEG tries to play the
    audio DIRECTLY through SDL… If you’re using SDL_mixer, you need to
    play through SDL_mixer instead…

  2. You need to cross hook the SMPEG output to the SDL_mixer input…

Check out smpeg/README.SDL_mixer for details…

-Loren

On Mon, 2002-12-16 at 17:13, Robert Diel wrote:

Hello all,
I have been trying to use smpeg and SDL_Mixer together and have had
very little luck. I was wondering if anyone has any tips. If I open
the mixer any audio output from my smpeg goes very slowly. If I do not
open the mixer and just use smpeg the audio plays fine. Am I doing
something incorrectly. plaympeg says the audio is “Audio MPEG-1 Layer 2
224kbit/s 44100Hz stereo”. I set my MIX_OpenAudio to:

if(Mix_OpenAudio(441000, MIX_DEFAULT_FORMAT, 2, 1024)

and it goes really slowly. Now, does MIX just take up that much extra
processing, or doesn’t it play well with mixer, or do I have a setting
wrong?

My guess, is that both smpeg and Mix are trying to service the same
resource, the sound buffer, and at double the processing, we have double
the cost. I am hoping this assumption is wrong and that I just have a
Mixer setting wrong, and that I don’t have to design my own.

Robert


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl