 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
saulotmalo2
Joined: 10 Sep 2007 Posts: 43
|
Posted: Tue Sep 25, 2007 9:19 am Post subject: how can I play two big sound files at the same time ? |
|
|
Hello, I usually use SDL_mixer when I have to work with sound. But now I'm having a problem. as SDL_mixer uses only one channel for the music i can't play two big music files (such as ogg of about 2 Mb) at the same time because I can't put them on chunks and if I play one on the music then the other one sounds bad.
there is a way on SDL or any other PSP library for get working both musics?
thanks |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Tue Sep 25, 2007 9:57 am Post subject: |
|
|
You could always decode one of them yourself, and submit it to SDL as "normal" audio samples.
There are a number of audio compression libs in the sdk - ogg/vorbis, tremor (integer based vorbis), and mad. |
|
| Back to top |
|
 |
saulotmalo2
Joined: 10 Sep 2007 Posts: 43
|
Posted: Tue Sep 25, 2007 10:23 am Post subject: |
|
|
I have never worked with sound using sdl only I've ever used SDL_mixer. Do you know where can i find information for do this?
thanks |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Tue Sep 25, 2007 10:30 am Post subject: |
|
|
| You can start by clicking the "search" button. |
|
| Back to top |
|
 |
saulotmalo2
Joined: 10 Sep 2007 Posts: 43
|
Posted: Tue Sep 25, 2007 11:05 am Post subject: |
|
|
| before posting I always try to find by myself... |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Tue Sep 25, 2007 11:46 am Post subject: |
|
|
Well, here's a thread on decoding ogg with tremor (comes right up in search, plus it's on the first page of post).
http://forums.ps2dev.org/viewtopic.php?t=8940
If you already know how to mix sound in sdl/sdl-mixer/whatever, just use the info in that thread (at the bottom) to see how tremor decodes the data. |
|
| Back to top |
|
 |
saulotmalo2
Joined: 10 Sep 2007 Posts: 43
|
Posted: Tue Sep 25, 2007 12:32 pm Post subject: |
|
|
yes, i saw this code this afternoon but and i dit this code:
| Code: | #include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <pspdisplay.h>
#include <psppower.h>
#include <psprtc.h>
#include <png.h>
#include <SDL.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string>
#include <list>
#include <iostream>
#include <fstream>
#include <SDL_mixer.h>
#include <pspaudio.h>
#include "tremor/ivorbiscodec.h"
#include "tremor/ivorbisfile.h"
using namespace std;
using namespace ftr;
PSP_MODULE_INFO("Test", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
#define OUTPUT_BUFFER 4*1024
/////////////////////////////////////////////////////////////////////////////////////////
//Globals
/////////////////////////////////////////////////////////////////////////////////////////
int runningFlag = 1;
OggVorbis_File OGG_VorbisFile;
int OGG_eos = 0;
int OGG_audio_channel = 0;
char pcmout[OUTPUT_BUFFER]; //for ov_read
char pcmoutBlock[OUTPUT_BUFFER]; //for real output
int bitStream;
static FILE *OGG_file = 0;
int bufferEmpty;
int bufferFull;
long bytesRed = 0;
///////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
//Globals
/////////////////////////////////////////////////////////////////////////////////////////
int runningFlag2 = 1;
OggVorbis_File OGG_VorbisFile2;
int OGG_eos2 = 0;
int OGG_audio_channel2 = 0;
char pcmout2[OUTPUT_BUFFER]; //for ov_read
char pcmoutBlock2[OUTPUT_BUFFER]; //for real output
int bitStream2;
static FILE *OGG_file2 = 0;
int bufferEmpty2;
int bufferFull2;
long bytesRed2 = 0;
///////////////////////////////////////////////////////////////////////////////////////////
int iteraciones=0;
static bool isrunning = true;
static int curWindow = 1;
int canal;
Mix_Music *sonido2;
int exit_callback(int arg1, int arg2, void *common) {
isrunning = false;
sceKernelExitGame();
return 0;
}
// Callback thread
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
// Sets up the callback thread and returns its thread id
int SetupCallbacks(void) {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
SDL_Surface * s;
//Animaciones animaciones;
/////////////////////////////////////////////////////////////////////////////////////////
//Buffer filling
/////////////////////////////////////////////////////////////////////////////////////////
int fillBuffer(SceSize args, void *argp){
bufferEmpty = sceKernelCreateSema("bufferEmpty", 0, 1, 1, 0);
while(runningFlag){
sceKernelWaitSema(bufferEmpty, 1, 0);
bytesRed = ov_read(&OGG_VorbisFile,pcmout,sizeof(pcmout),&bitStream);
switch (bytesRed){
case 0:
//EOF:
OGG_eos = 1;
ov_clear(&OGG_VorbisFile);
sceKernelSignalSema(bufferFull, 1);
break;
case OV_HOLE:
case OV_EBADLINK:
sceKernelSignalSema(bufferEmpty, 1);
break;
default:
sceKernelSignalSema(bufferFull, 1);
break;
}
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
//Buffer filling 2
/////////////////////////////////////////////////////////////////////////////////////////
int fillBuffer2(SceSize args, void *argp){
bufferEmpty2 = sceKernelCreateSema("bufferEmpty", 0, 1, 1, 0);
while(runningFlag2){
sceKernelWaitSema(bufferEmpty2, 1, 0);
bytesRed2 = ov_read(&OGG_VorbisFile2,pcmout2,sizeof(pcmout2),&bitStream2);
switch (bytesRed2){
case 0:
//EOF:
OGG_eos2 = 1;
ov_clear(&OGG_VorbisFile2);
sceKernelSignalSema(bufferFull2, 1);
break;
case OV_HOLE:
case OV_EBADLINK:
sceKernelSignalSema(bufferEmpty2, 1);
break;
default:
sceKernelSignalSema(bufferFull2, 1);
break;
}
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
//Audio output
/////////////////////////////////////////////////////////////////////////////////////////
int audioOutput(SceSize args, void *argp){
bufferFull = sceKernelCreateSema("bufferFull", 0, 0, 1, 0);
while(runningFlag){
sceKernelWaitSema(bufferFull, 1, 0);
if (OGG_eos)
break;
memcpy(pcmoutBlock,pcmout,OUTPUT_BUFFER);
sceKernelSignalSema(bufferEmpty, 1);
sceAudioSetChannelDataLen(OGG_audio_channel, bytesRed/4);
sceAudioOutputBlocking(OGG_audio_channel, PSP_AUDIO_VOLUME_MAX, pcmoutBlock);
}
return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
//Audio output
/////////////////////////////////////////////////////////////////////////////////////////
int audioOutput2(SceSize args, void *argp){
bufferFull2 = sceKernelCreateSema("bufferFull", 0, 0, 1, 0);
while(runningFlag2){
sceKernelWaitSema(bufferFull2, 1, 0);
if (OGG_eos2)
break;
memcpy(pcmoutBlock2,pcmout2,OUTPUT_BUFFER);
sceKernelSignalSema(bufferEmpty2, 1);
sceAudioSetChannelDataLen(OGG_audio_channel2, bytesRed2/4);
sceAudioOutputBlocking(OGG_audio_channel2, PSP_AUDIO_VOLUME_MAX, pcmoutBlock2);
}
return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////
void pruebaAlgo(SDL_Event * evento)
{
iteraciones++;
cout<<iteraciones<<endl;
if(iteraciones==50000){
int bufferThid2 = sceKernelCreateThread("bufferFilling", fillBuffer2, 0x12, 0x10000, PSP_THREAD_ATTR_USER, NULL);
if(bufferThid2 < 0){
}
sceKernelStartThread(bufferThid2, 0, NULL);
//Start audio output thread:
int audioThid2 = sceKernelCreateThread("audioOutput", audioOutput2, 0x16, 0x1800, PSP_THREAD_ATTR_USER, NULL);
if(audioThid2 < 0) {}
sceKernelStartThread(audioThid2, 0, NULL);
}
switch (evento->type)
{
case SDL_QUIT:
exit(0);
break;
case SDL_KEYDOWN:
if (evento->key.keysym.sym == SDLK_q)
{
exit(0);
}
//if (evento->key.keysym.sym == SDLK_d)
// Aplicacion::instance().setBanderasDepuracion(Aplicacion::BD_INTERACTIVO);
//if (evento->key.keysym.sym == SDLK_s)
// Aplicacion::instance().setBanderasDepuracion(Aplicacion::BD_NADA);
}
}
int main() {
//Initialize the controler and the PSP Speed
SDL_Joystick *joystick;
SceCtrlData pad;
scePowerSetClockFrequency(333, 333, 333);
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
//Aplicacion & app = Aplicacion::instance();
//app.inicializar();
//Initialize the SDL Library (audio and video)
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK ) < 0)
cout << stderr << "Couldn't initialize SDL: " << SDL_GetError() << endl;
SDL_Surface *ecran = SDL_SetVideoMode(480, 272, 16, SDL_SWSURFACE );
// atexit(Mix_CloseAudio);
SDL_JoystickEventState(SDL_ENABLE);
joystick = SDL_JoystickOpen(0);
pspDebugScreenInit();
SetupCallbacks();
//Apro il file OGG:
OGG_file = fopen("jump.ogg", "r");
if ((OGG_file) != NULL) {
ov_open(OGG_file, &OGG_VorbisFile, NULL, 0);
}else{
return -1;
}
OGG_file2 = fopen("jump.ogg", "r");
if ((OGG_file2) != NULL) {
ov_open(OGG_file2, &OGG_VorbisFile2, NULL, 0);
}else{
return -1;
}
//Reserve audio channel:
OGG_audio_channel = sceAudioChReserve(OGG_audio_channel, OUTPUT_BUFFER/4, PSP_AUDIO_FORMAT_STEREO);
OGG_audio_channel2 = sceAudioChReserve(OGG_audio_channel2, OUTPUT_BUFFER/4, PSP_AUDIO_FORMAT_STEREO);
//Start buffer filling thread:
int bufferThid = sceKernelCreateThread("bufferFilling", fillBuffer, 0x12, 0x10000, PSP_THREAD_ATTR_USER, NULL);
if(bufferThid < 0)
return -1;
sceKernelStartThread(bufferThid, 0, NULL);
//Start audio output thread:
int audioThid = sceKernelCreateThread("audioOutput", audioOutput, 0x16, 0x1800, PSP_THREAD_ATTR_USER, NULL);
if(audioThid < 0)
return -1;
sceKernelStartThread(audioThid, 0, NULL);
while(isrunning)
{
sceCtrlReadBufferPositive(&pad, 1);
SDL_Event evento;
/* Loop waiting for ESC+Mouse_Button */
while ( SDL_PollEvent(&evento) >= 0 ) {
pruebaAlgo(&evento);
}
}
sceAudioChRelease(OGG_audio_channel);
SDL_Quit();
sceKernelSleepThread();
return 0;
}
|
I have tried to duplicate every thing in the fuction, usually I'm not working this way but I'm in a hurry by trying this proyect it is important for me to have it by the weekend. Well as I was telling, I've tried to make the same that do the threads of filling the buffer but changing the name of everyting. And when the iteration gets 50000 start the new threads... but when I do this sound begins to get bad :(. |
|
| Back to top |
|
 |
gambiting
Joined: 17 Aug 2006 Posts: 154
|
Posted: Sun Sep 30, 2007 1:59 am Post subject: |
|
|
| Use OSLib,it allows you to play many files at once,without size limit(you can load them to ram or stream from ms). |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Sun Sep 30, 2007 11:24 am Post subject: |
|
|
| The code above is using old non-working-right code. Use the latest code from the last post I made in the thread indicated. That has all the bugs worked out with proper sounding audio. |
|
| Back to top |
|
 |
saulotmalo2
Joined: 10 Sep 2007 Posts: 43
|
Posted: Sun Sep 30, 2007 1:39 pm Post subject: |
|
|
thanks both. I'll try tomorow when I get up and my head dodn't tell me to kill me( how it is called in english? resaca yeah you know when you drunk a lot in spanish is called).
truly thanks... tomorrow i'll try both |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|