~ubuntu-branches/ubuntu/vivid/basilisk2/vivid

« back to all changes in this revision

Viewing changes to src/MacOSX/MacOSX_sound_if.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-03-06 19:33:01 UTC
  • mfrom: (2.1.4 gutsy)
  • Revision ID: james.westby@ubuntu.com-20080306193301-cc2ofn705nfsq3y0
Tags: 0.9.20070407-4
* Update copyright-check cdbs snippet to parse licensecheck using perl:
  + No longer randomly drops newlines
  + More compact hint file (and ordered more like wiki-proposed new copyright
    syntax).
  + No longer ignore files without copyright.
* Update copyright_hints.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  MacOSX_sound_if.h
 
3
 *  BasiliskII
 
4
 *
 
5
 *  Copyright 2006 Daniel Sumorok. All rights reserved.
 
6
 *
 
7
 *  This program is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License as published by
 
9
 *  the Free Software Foundation; either version 2 of the License, or
 
10
 *  (at your option) any later version.
 
11
 *
 
12
 *  This program is distributed in the hope that it will be useful,
 
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *  GNU General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU General Public License
 
18
 *  along with this program; if not, write to the Free Software
 
19
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
20
 */
 
21
#include "AudioBackEnd.h"
 
22
#include "MacOSX_sound_if.h"
 
23
 
 
24
OSXsoundOutput::OSXsoundOutput() :
 
25
  player(NULL),
 
26
  callback(NULL) {
 
27
}
 
28
 
 
29
void OSXsoundOutput::getMoreSamples(void *arg) {
 
30
  OSXsoundOutput *me;
 
31
        
 
32
  me = (OSXsoundOutput *)arg;
 
33
        
 
34
  if(me == NULL) {
 
35
    return;
 
36
  }
 
37
        
 
38
  if(me->callback == NULL) {
 
39
    return;
 
40
  }
 
41
        
 
42
  me->callback();
 
43
}
 
44
 
 
45
int OSXsoundOutput::start(int bitsPerSample, int numChannels, int sampleRate) {
 
46
  stop();
 
47
  player = new AudioBackEnd(bitsPerSample, numChannels, sampleRate);
 
48
  if(player != NULL) {
 
49
    player->setCallback(getMoreSamples, (void *)this);
 
50
    player->Start();
 
51
  }
 
52
  return 0;
 
53
}
 
54
 
 
55
int OSXsoundOutput::stop() {
 
56
  if(player != NULL) {
 
57
    player->Stop();
 
58
    delete player;
 
59
    player = NULL;
 
60
  }
 
61
  return 0;
 
62
}
 
63
 
 
64
OSXsoundOutput::~OSXsoundOutput() {
 
65
  stop();
 
66
}
 
67
 
 
68
void OSXsoundOutput::setCallback(audioCallback fn) {
 
69
  callback = fn;
 
70
}
 
71
 
 
72
unsigned int OSXsoundOutput::bufferSizeFrames() {
 
73
  if(player != NULL) {
 
74
    return player->BufferSizeFrames();
 
75
  }
 
76
        
 
77
  return 0;
 
78
}
 
79
 
 
80
int OSXsoundOutput::sendAudioBuffer(void *buffer, int numFrames) {
 
81
  if(player != NULL) {
 
82
    return player->sendAudioBuffer(buffer, numFrames);
 
83
  }
 
84
        
 
85
  return 0;
 
86
}