~registry/dolphin-emu/triforce

« back to all changes in this revision

Viewing changes to Source/Core/AudioCommon/Src/AOSoundStream.cpp

  • Committer: Sérgio Benjamim
  • Date: 2015-02-13 05:54:40 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20150213055440-ey2rt3sjpy27km78
Dolphin Triforce branch from code.google, commit b957980 (4.0-315).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Dolphin Emulator Project
 
2
// Licensed under GPLv2
 
3
// Refer to the license.txt file included.
 
4
 
 
5
#include <functional>
 
6
#include <string.h>
 
7
 
 
8
#include "AOSoundStream.h"
 
9
#include "Mixer.h"
 
10
 
 
11
#if defined(HAVE_AO) && HAVE_AO
 
12
 
 
13
void AOSound::SoundLoop()
 
14
{
 
15
        Common::SetCurrentThreadName("Audio thread - ao");
 
16
 
 
17
        uint_32 numBytesToRender = 256;
 
18
        ao_initialize();
 
19
        default_driver = ao_default_driver_id();
 
20
        format.bits = 16;
 
21
        format.channels = 2;
 
22
        format.rate = m_mixer->GetSampleRate();
 
23
        format.byte_format = AO_FMT_LITTLE;
 
24
 
 
25
        device = ao_open_live(default_driver, &format, NULL /* no options */);
 
26
        if (!device)
 
27
        {
 
28
                PanicAlertT("AudioCommon: Error opening AO device.\n");
 
29
                ao_shutdown();
 
30
                Stop();
 
31
                return;
 
32
        }
 
33
 
 
34
        buf_size = format.bits/8 * format.channels * format.rate;
 
35
 
 
36
        while (!threadData)
 
37
        {
 
38
                m_mixer->Mix(realtimeBuffer, numBytesToRender >> 2);
 
39
 
 
40
                {
 
41
                std::lock_guard<std::mutex> lk(soundCriticalSection);
 
42
                ao_play(device, (char*)realtimeBuffer, numBytesToRender);
 
43
                }
 
44
 
 
45
                soundSyncEvent.Wait();
 
46
        }
 
47
}
 
48
 
 
49
bool AOSound::Start()
 
50
{
 
51
        memset(realtimeBuffer, 0, sizeof(realtimeBuffer));
 
52
 
 
53
        thread = std::thread(std::mem_fun(&AOSound::SoundLoop), this);
 
54
        return true;
 
55
}
 
56
 
 
57
void AOSound::Update()
 
58
{
 
59
        soundSyncEvent.Set();
 
60
}
 
61
 
 
62
void AOSound::Stop()
 
63
{
 
64
        threadData = 1;
 
65
        soundSyncEvent.Set();
 
66
 
 
67
        {
 
68
        std::lock_guard<std::mutex> lk(soundCriticalSection);
 
69
        thread.join();
 
70
 
 
71
        if (device)
 
72
                ao_close(device);
 
73
 
 
74
        ao_shutdown();
 
75
 
 
76
        device = NULL;
 
77
        }
 
78
}
 
79
 
 
80
AOSound::~AOSound()
 
81
{
 
82
}
 
83
 
 
84
#endif