コード例 #1
0
ファイル: SdlMusPlayer.cpp プロジェクト: tcvicio/PGE-Project
int PGE_MusPlayer::initAudio(int sampleRate, int allocateChannels, int bufferSize)
{
    int ret=0;
    sRate=sampleRate;

    MIX_Timidity_addToPathList(QString(ApplicationPath+"/timidity/").toLocal8Bit().data());
    if(isLoaded) Mix_CloseAudio();
    ret = Mix_OpenAudio(sRate, AUDIO_S16, 2, bufferSize);
    if(ret==-1) return ret;
    Mix_AllocateChannels(allocateChannels);

    // Reset the audio sample count and set the post mix callback
    if (sampleCountMutex == NULL)
    {
        sampleCountMutex = SDL_CreateMutex();
    }
    // Reset music sample count
    if (SDL_LockMutex(sampleCountMutex) == 0)
    {
        sCount = 0;
        musSCount = 0;
        Mix_SetPostMix(postMixCallback, NULL);
        SDL_UnlockMutex(sampleCountMutex);
    }
    isLoaded = true;
    return ret;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: zigurana/PGE-Project
int main(int argc, char *argv[])
{
    QApplication::addLibraryPath( "." );
    QApplication::addLibraryPath( QFileInfo(QString::fromUtf8(argv[0])).dir().path() );
    QApplication::addLibraryPath( QFileInfo(QString::fromLocal8Bit(argv[0])).dir().path() );

    QApplication a(argc, argv);
    QStringList args=a.arguments();
    SingleApplication *as = new SingleApplication(args);
    if(!as->shouldContinue())
    {
        QTextStream(stdout) << "SDL2 Mixer X Player already runned!\n";
        delete as;
        return 0;
    }

    #ifdef Q_OS_LINUX
    a.setStyle("GTK");
    #endif

    if(SDL_Init(SDL_INIT_AUDIO)==-1)
        error(SDL_GetError());

    if(Mix_Init(MIX_INIT_FLAC | MIX_INIT_MP3 | MIX_INIT_OGG | MIX_INIT_MODPLUG )==-1)
        error(Mix_GetError());

    qDebug() << QString(a.applicationDirPath()+"/timidity/");
    MIX_Timidity_addToPathList(QString(a.applicationDirPath()+"/timidity/").toLocal8Bit().data());

    if(Mix_OpenAudio(44100, AUDIO_S16, 2, 4096)==-1)
        error(Mix_GetError());

    //Disallow auto-resetting MIDI properties (to allow manipulation with MIDI settings by functions)
    MIX_SetLockMIDIArgs(1);

    MainWindow w;

    //Set acception of external file openings
    w.connect(as, SIGNAL(openFile(QString)), &w, SLOT(openMusicByArg(QString)));

    w.show();
    if(a.arguments().size()>1)
        w.openMusicByArg(a.arguments()[1]);

    int result = a.exec();
    delete as;
    SDL_Quit();
    return result;
}
コード例 #3
0
void PGE_MusPlayer::setSampleRate(int sampleRate=44100)
{
    sRate=sampleRate;
    #ifdef USE_SDL_MIXER
    qDebug() << "Set sample rate to:"<<sampleRate;

    MIX_Timidity_addToPathList(QString(ApplicationPath+"/timidity/").toLocal8Bit().data());
    if(Mix_OpenAudio(sRate, AUDIO_S16, 2, 4096)<0)
    {
        LogWarning(QString("Can't open audio: %1").arg(Mix_GetError()));
    }
    if(Mix_AllocateChannels(16)<0)
    {
        LogWarning(QString("Can't allocate channels: %1").arg(Mix_GetError()));
    }
    #endif
}