Add support for managing mixer knobs to snd interface
This commit is contained in:
parent
5d4f63356a
commit
ad708efd5a
@ -4,14 +4,29 @@
|
||||
/* The format isn't really used for anything right now */
|
||||
#define SND_FORMAT_L16SLE 0 /* Linear 16-bit signed little endian */
|
||||
|
||||
#include <lib/snd.h>
|
||||
#include <logging.h>
|
||||
#include <system.h>
|
||||
|
||||
#define SND_KNOB_VENDOR 1024
|
||||
|
||||
typedef uint16_t snd_mixer_enum_t;
|
||||
|
||||
typedef struct snd_knob {
|
||||
char name[SND_KNOB_NAME_SIZE];
|
||||
uint32_t id;
|
||||
} snd_knob_t;
|
||||
|
||||
typedef struct snd_device {
|
||||
char name[256]; /* Name of the device. */
|
||||
void * device; /* Private data for the device. May be NULL. */
|
||||
uint32_t playback_speed; /* Playback speed in Hz */
|
||||
uint32_t playback_format; /* Playback format (SND_FORMAT_*) */
|
||||
|
||||
snd_knob_t *knobs;
|
||||
uint32_t num_knobs;
|
||||
int (*mixer_read)(uint32_t knob_id, uint32_t *val);
|
||||
int (*mixer_write)(uint32_t knob_id, uint32_t val);
|
||||
} snd_device_t;
|
||||
|
||||
/*
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <mod/snd.h>
|
||||
|
||||
#include <list.h>
|
||||
#include <mod/shell.h>
|
||||
#include <module.h>
|
||||
#include <ringbuffer.h>
|
||||
#include <system.h>
|
||||
@ -140,8 +141,41 @@ int snd_request_buf(snd_device_t * device, uint32_t size, uint8_t *buffer) {
|
||||
return size;
|
||||
}
|
||||
|
||||
static snd_device_t * snd_main_device() {
|
||||
spin_lock(&_devices_lock);
|
||||
foreach(node, &_devices) {
|
||||
spin_unlock(&_devices_lock);
|
||||
return node->value;
|
||||
}
|
||||
|
||||
spin_unlock(&_devices_lock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DEFINE_SHELL_FUNCTION(snd_full, "[debug] turn snd master to full") {
|
||||
snd_main_device()->mixer_write(SND_KNOB_MASTER, UINT32_MAX);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_SHELL_FUNCTION(snd_half, "[debug] turn snd master to half") {
|
||||
snd_main_device()->mixer_write(SND_KNOB_MASTER, UINT32_MAX / 2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_SHELL_FUNCTION(snd_off, "[debug] turn snd master to lowest volume") {
|
||||
snd_main_device()->mixer_write(SND_KNOB_MASTER, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int init(void) {
|
||||
vfs_mount("/dev/dsp", &_main_fnode);
|
||||
|
||||
BIND_SHELL_FUNCTION(snd_full);
|
||||
BIND_SHELL_FUNCTION(snd_half);
|
||||
BIND_SHELL_FUNCTION(snd_off);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
37
userspace/lib/snd.h
Normal file
37
userspace/lib/snd.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef USERSPACE_LIB_SND_H
|
||||
#define USERSPACE_LIB_SND_H
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#define SND_MAX_KNOBS 256
|
||||
#define SND_KNOB_NAME_SIZE 256
|
||||
|
||||
#define SND_KNOB_MASTER 0
|
||||
#define SND_DEVICE_MAIN 0
|
||||
|
||||
typedef struct snd_knob_list {
|
||||
uint32_t device;
|
||||
uint32_t num;
|
||||
uint32_t ids[SND_MAX_KNOBS];
|
||||
} snd_knob_list_t;
|
||||
|
||||
typedef struct snd_knob_info {
|
||||
uint32_t device;
|
||||
uint32_t id;
|
||||
char name[SND_KNOB_NAME_SIZE];
|
||||
} snd_knob_info_t;
|
||||
|
||||
typedef struct snd_knob_value {
|
||||
uint32_t device;
|
||||
uint32_t id;
|
||||
uint32_t val;
|
||||
} snd_knob_value_t;
|
||||
|
||||
|
||||
/* IOCTLs */
|
||||
#define SND_MIXER_GET_KNOBS 0
|
||||
#define SND_MIXER_GET_KNOB_INFO 1
|
||||
#define SND_MIXER_READ_KNOB 2
|
||||
#define SND_MIXER_WRITE_KNOB 3
|
||||
|
||||
#endif /* USERSPACE_LIB_SND_H */
|
Loading…
Reference in New Issue
Block a user