summaryrefslogtreecommitdiffstats
path: root/branches/lydia/sound_decoder.cpp
blob: e284ccbfeaf81af52d7f301073a651baaf20c2b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

// "$Id: decoder.cpp 328 2004-02-13 16:58:16Z jaromil $"

#include <sound_device.h>
#include <sound_decoder.h>
#include <utils.h>

MuseDec::MuseDec() 
  : Thread() {
    bitrate = samplerate = channels = frames = 0;
    seekable = false; err = false; eos = false;
    loaded = false;

    device = NULL;
}

MuseDec::~MuseDec() { }

bool MuseDec::play_once(SoundDevice *dev) {
  seek(0.0);
  replay = true;
  eos = false;
  device = dev;
  launch();
  return true;
}

void MuseDec::run() {
  D("Sound file decoder thread launched");
  IN_DATATYPE *buf;

  if(!device) {
    E("no device configured for decoder");
    return;
  }

  while(true) {

    while(!replay) { jsleep(0,500); }
    
    while(!eos) {
      
      buf = get_audio();
      
      if(!buf) break;
      
      device->write(buf, IN_CHUNK);
      
      //    device->flush_output();
      
    }
    replay = false;
    eos = false;
    seek(0.0);

  }

  return;
}