Example #1
0
void OpenAlSoundDriver::open_sound(PrintItem path, scoped_ptr<Sound>& sound) {
    scoped_ptr<OpenAlSound> result(new OpenAlSound(*this));
    Resource rsrc(path);
    AudioFile audio_file(rsrc.data());
    result->buffer(audio_file);
    sound.reset(result.release());
}
Example #2
0
void MarkovPlayer::WriteFinalSignals()
{
    std::string dir = MACHINEPATH;
    const int format=SF_FORMAT_WAV | SF_FORMAT_PCM_16;
    const int channels=1;
    const int sampleRate=44100;
    dir.append("Final Tracks/");
    char buf[10];
    for(int i = 0 ; i < n_sequences; i++){
        printf("Writing signals %d...\n",i);
        sprintf(buf, "%d", i);
        std::string audio_path = dir;
        audio_path.append(buf);
        audio_path.append(".wav");
        SndfileHandle audio_file(audio_path, SFM_WRITE, format, channels, sampleRate);
        audio_file.write(&abs_signal[i][0], abs_signal[0].size());
        printf("Signal write complete\n");
    }
       
}
Example #3
0
void Sound::run() {
    QFile audio_file(mResourcePath);
    if(audio_file.open(QIODevice::ReadOnly)) {
        QByteArray audio_data = audio_file.readAll();
        audio_file.close();

        ALuint src, buf;

        buf = alureCreateBufferFromMemory((const unsigned char*)audio_data.constData(), audio_data.size());

        alGenSources(1, &src);
        if(alGetError() != AL_NO_ERROR) {
            qDebug() << "Failed to create OpenAL source!";
        }

        if(!buf) {
            qDebug() << "Could not load sound: " << alureGetErrorString();
            alDeleteSources(1, &src);
        }

        alSourcei(src, AL_BUFFER, buf);
        alSourcef(src, AL_GAIN, 0.8f * mVolume);
        if(alurePlaySource(src, eos_callback, this) == AL_FALSE) {
            qDebug() << "Failed to start source!";
            alDeleteSources(1, &src);
            alDeleteBuffers(1, &buf);
        }

        while(!mIsDone) {
            alureSleep(0.125);
            alureUpdate();
        }

        alDeleteSources(1, &src);
        alDeleteBuffers(1, &buf);
    }
}
Example #4
0
bool injectXml(QString defaultFile, QStringList fileList, QString fileSuffix){
    qDebug() << "Injecting" << fileList.count() << "audio files into" << fileSuffix;
    // Open default xml file and make a list of all tags
    QFile audio_file(defaultFile);
    if(!audio_file.open(QIODevice::ReadOnly)){
        return false;
    }
    QDomDocument audio;
    audio.setContent(&audio_file);
    audio_file.close();

    QString root_tag = getRootTag(fileSuffix);
    QString start_tag = getStartTag(fileSuffix);
    QString id_tag = getIDTag(fileSuffix);

    QStringList audio_tag_list;
    QDomElement audio_tag;
    if(fileSuffix == "AudioDefines.xml"){
        audio_tag = audio.firstChildElement(root_tag).firstChildElement("SoundDatas").firstChildElement(start_tag).toElement();
    }
    else{
        audio_tag = audio.firstChildElement(root_tag).firstChildElement(start_tag).toElement();
    }
    for(;!audio_tag.isNull();audio_tag = audio_tag.nextSiblingElement()){
        // Check if tag exists in the base file
        audio_tag_list << audio_tag.firstChildElement(id_tag).firstChild().nodeValue();
    }

    // List all files with the right suffix
    int total_new = 0;
    foreach(QString fileName, fileList){
        // For each file, for each tag ID, check if exists and inject all dependencies if not.
        if(fileName.endsWith(fileSuffix)){
            QFile file(fileName);
            file.open(QIODevice::ReadOnly);
            QDomDocument xml;
            xml.setContent(&file);
            file.close();
            QDomElement entity;
            if(fileSuffix == "AudioDefines.xml"){
                entity = xml.firstChildElement(root_tag).firstChildElement("SoundDatas").firstChildElement(start_tag).toElement();
            }
            else{
                entity = xml.firstChildElement(root_tag).firstChildElement(start_tag).toElement();
            }
            QList<QDomElement> node_list;
            for(entity;!entity.isNull();entity = entity.nextSiblingElement()){
                // Check if tag exists in the base file
                QString tag = entity.firstChildElement(id_tag).firstChild().nodeValue();
                int j = 0;
                foreach(QString entry, audio_tag_list){
                    if(entry == tag){
                        j++;
                    }
                }
                if(j == 0){
                    total_new++;
                    // Inject all dependencies to the xml file
                    audio_tag_list << tag;
                    node_list << entity;
                }
            }
            foreach(QDomElement element, node_list){
            if(fileSuffix == "AudioDefines.xml"){
                audio.firstChildElement(root_tag).firstChildElement("SoundDatas").appendChild(element);
            }
            else{
                audio.firstChildElement(root_tag).appendChild(element);
            }
            }
        }
    }