File: audiodrv.cpp

package info (click to toggle)
sidplay 1.36.28-2
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,192 kB
  • ctags: 1,674
  • sloc: cpp: 12,514; sh: 1,716; makefile: 223
file content (90 lines) | stat: -rw-r--r-- 1,765 bytes parent folder | download | duplicates (9)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// 1997/09/27 21:38:01
//

#include "audiodrv.h"

audioDriver::audioDriver()
{
	// Reset everything.
	errorString = "None";
	frequency = 0;
	channels = 0;
	encoding = 0;
	precision = 0;
	audio = (config = NULL);
}

bool audioDriver::IsThere()
{
	// Check device availability and write permissions.
	return (access(AUDIODEVICE,W_OK)==0);
}

bool audioDriver::Open(udword inFreq, int inPrecision, int inChannels,
					   int inFragments, int inFragBase)
{
	// Transfer input parameters to this object.
	// May later be replaced with driver defaults.
	frequency = inFreq;

	long chpars[] = {AL_OUTPUT_RATE, 0};
 
	// Frequency
 
	chpars[1] = frequency;
	ALsetparams(AL_DEFAULT_DEVICE, chpars, 2);
	ALgetparams(AL_DEFAULT_DEVICE, chpars, 2);
	config = ALnewconfig();
 
	// Set sample format
 
	ALsetsampfmt(config, AL_SAMPFMT_TWOSCOMP);
	encoding = SIDEMU_SIGNED_PCM;  // unlike other systems
	
	// Mono output
 
	ALsetchannels(config, AL_MONO);
	channels = SIDEMU_MONO;
 
	// 8-bit sampleSize
 
	ALsetwidth(config, AL_SAMPLE_8);
	precision = SIDEMU_8BIT;
 
	// Allocate an audio port
 
	if((audio = ALopenport("SIDPLAY sound", "w", config)) == NULL)
    {
		errorString = "AUDIO: Could not open audio port.";
		oserror();
		ALfreeconfig(config);
		return false;  //(1);
    }
 
	// Allocate sound buffers
	blockSize = frequency;
	ALsetqueuesize(config,blockSize);
	
	return true;
}

// Close an opened audio device, free any allocated buffers and
// reset any variables that reflect the current state.
void audioDriver::Close()
{
	if (audio != NULL)
    {
		ALcloseport(audio);
		ALfreeconfig(config);
		audio = (config = NULL);
    }
}

void audioDriver::Play(ubyte* pBuffer, int bufferSize)
{
	if (audio != NULL)
	{
		ALwritesamps(audio,pBuffer,bufferSize);
	}
}