blob: 2d32b1fc7808389a07e47893858d538f7f4adb0f (
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
|
#include <stdio.h>
#include <sys/ioctl.h>
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/soundcard.h>
#include "sound_output.h"
static int32_t oss_audio_fd = -1;
uint32_t Audio_Init()
{
uint32_t channels = 2;
uint32_t format = AFMT_S16_LE;
uint32_t tmp = SOUND_OUTPUT_FREQUENCY;
int32_t err_ret;
oss_audio_fd = open("/dev/dsp", O_WRONLY | O_NONBLOCK);
if (oss_audio_fd < 0)
{
printf("Couldn't open /dev/dsp.\n");
return 1;
}
err_ret = ioctl(oss_audio_fd, SNDCTL_DSP_SPEED,&tmp);
if (err_ret == -1)
{
printf("Could not set sound frequency\n");
return 1;
}
err_ret = ioctl(oss_audio_fd, SNDCTL_DSP_CHANNELS, &channels);
if (err_ret == -1)
{
printf("Could not set channels\n");
return 1;
}
err_ret = ioctl(oss_audio_fd, SNDCTL_DSP_SETFMT, &format);
if (err_ret == -1)
{
printf("Could not set sound format\n");
return 1;
}
return 0;
}
void Audio_Write(int16_t* restrict buffer, uint32_t buffer_size)
{
write(oss_audio_fd, buffer, buffer_size * 4 );
}
void Audio_Close()
{
if (oss_audio_fd >= 0)
{
close(oss_audio_fd);
oss_audio_fd = -1;
}
}
|