Skip to content

Commit

Permalink
virtio_sound: playback and recording reimagined.
Browse files Browse the repository at this point in the history
Fixes #3, implements #2 and #1.

Implements suggestions from korli in mentioned issues.

Recording functionality was added, there's still
work to do, performace is not where it should be.

Signed-off-by: Diego Roux <diegoroux04@protonmail.com>
  • Loading branch information
diegoroux committed Jul 24, 2024
1 parent b3a98e8 commit 01f627f
Show file tree
Hide file tree
Showing 4 changed files with 401 additions and 83 deletions.
35 changes: 35 additions & 0 deletions src/add-ons/kernel/drivers/audio/virtio/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ tx_queue_done(void* _cookie, void* __cookie)
}


static void
rx_queue_done(void* _cookie, void* __cookie)
{
VirtIOSoundDriverInfo* info = (VirtIOSoundDriverInfo*)__cookie;

release_sem_etc(info->rxSem, 1, B_DO_NOT_RESCHEDULE);
}


static status_t
virtio_snd_init_device(void* _info, void** cookie)
{
Expand Down Expand Up @@ -183,6 +192,12 @@ virtio_snd_init_device(void* _info, void** cookie)
goto err1;
}

status = info->virtio->queue_setup_interrupt(info->rxQueue, rx_queue_done, info);
if (status != B_OK) {
ERROR("rx queue interrupt setup failed (%s)\n", strerror(status));
goto err1;
}

status = info->virtio->queue_setup_interrupt(info->eventQueue, NULL, info);
if (status != B_OK) {
ERROR("event queue interrupt setup failed (%s)\n", strerror(status));
Expand Down Expand Up @@ -271,6 +286,7 @@ virtio_snd_uninit_device(void *_info)
return;
}


static status_t
virtio_snd_open(void *deviceCookie, const char *path, int openMode,
void **_cookie)
Expand All @@ -287,6 +303,22 @@ virtio_snd_open(void *deviceCookie, const char *path, int openMode,
}


static status_t
virtio_snd_read(void *cookie, off_t pos, void *buffer, size_t *_length)
{
*_length = 0;
return B_IO_ERROR;
}


static status_t
virtio_snd_write(void *cookie, off_t pos, const void *buffer, size_t *_length)
{
*_length = 0;
return B_IO_ERROR;
}


static status_t
virtio_snd_close(void* cookie)
{
Expand Down Expand Up @@ -337,6 +369,9 @@ struct device_module_info sVirtioSoundDevice = {

.free = virtio_snd_free_dev,

.read = virtio_snd_read,
.write = virtio_snd_write,

.control = virtio_snd_ctrl,
};

Expand Down
13 changes: 10 additions & 3 deletions src/add-ons/kernel/drivers/audio/virtio/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#define VIRTIO_SND_CHMAP_MAX_SIZE 18

#define FRAMES_PER_BUFFER 1024
#define FRAMES_PER_BUFFER (1024 * 16)
#define BUFFERS 2


Expand All @@ -37,6 +37,7 @@ struct VirtIOSoundPCMInfo {

uint32 format;
uint32 rate;
uint32 cvsr;

uint32 period_size;

Expand All @@ -52,9 +53,12 @@ struct VirtIOSoundPCMInfo {
uint32 real_time;
uint32 frames_count;

physical_entry entries[3];

uint8 chmap[VIRTIO_SND_CHMAP_MAX_SIZE];

area_id xferArea;
addr_t xferBuf;
phys_addr_t xferAddr;
spinlock xferLock;
};


Expand Down Expand Up @@ -93,10 +97,13 @@ struct VirtIOSoundDriverInfo {
addr_t txBuf;
phys_addr_t txAddr;
sem_id txSem;
thread_id txThread;

area_id rxArea;
addr_t rxBuf;
phys_addr_t rxAddr;
sem_id rxSem;
thread_id rxThread;
};

status_t
Expand Down
Loading

0 comments on commit 01f627f

Please sign in to comment.