-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When using libusb, process commands asynchronously to reduce the effect of serial traffic on audio.
- Loading branch information
Showing
9 changed files
with
152 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <SDL.h> | ||
|
||
const int command_size = 4096; | ||
int write_cursor = 0; | ||
int read_cursor = 0; | ||
uint8_t **command_buffer; | ||
uint32_t *command_sizes; | ||
|
||
void command_queue_init() { | ||
command_buffer = SDL_malloc(command_size * sizeof(uint8_t *)); | ||
command_sizes = SDL_malloc(command_size * sizeof(uint32_t)); | ||
} | ||
|
||
void command_queue_destroy() { | ||
SDL_free(command_buffer); | ||
SDL_free(command_sizes); | ||
} | ||
|
||
int command_queue_push(uint8_t *data, uint32_t size) { | ||
uint8_t *recv_buf = SDL_malloc(size * sizeof(uint8_t)); | ||
SDL_memcpy(recv_buf, data, size); | ||
|
||
SDL_free(command_buffer[write_cursor % command_size]); | ||
command_buffer[write_cursor % command_size] = recv_buf; | ||
command_sizes[write_cursor % command_size] = size; | ||
write_cursor++; | ||
return 1; | ||
} | ||
|
||
int command_queue_pop(uint8_t **data, uint32_t *size) { | ||
int compare = write_cursor - read_cursor; | ||
if (compare == 0) { | ||
return 0; | ||
} | ||
*data = command_buffer[read_cursor % command_size]; | ||
*size = command_sizes[read_cursor % command_size]; | ||
read_cursor++; | ||
return compare; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef COMMAND_QUEUE_H_ | ||
#define COMMAND_QUEUE_H_ | ||
#include <stdint.h> | ||
|
||
void command_queue_init(); | ||
int command_queue_push(uint8_t *data, uint32_t size); | ||
int command_queue_pop(uint8_t **data, uint32_t *size); | ||
void command_queue_destroy(); | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters