make frequency variable
This commit is contained in:
parent
b86ad339d9
commit
df5b2e9b5c
1 changed files with 9 additions and 3 deletions
12
lib/main.c
12
lib/main.c
|
|
@ -9,6 +9,7 @@
|
|||
#define DEFAULT_RATE 44100
|
||||
#define DEFAULT_CHANNELS 2
|
||||
#define DEFAULT_VOLUME 0.7
|
||||
#define DEFAULT_FREQ 200
|
||||
|
||||
#define PWSTREAM_NAME "Dorne"
|
||||
|
||||
|
|
@ -16,6 +17,7 @@ struct data {
|
|||
struct pw_main_loop *loop;
|
||||
struct pw_stream *stream;
|
||||
double accumulator;
|
||||
uint32_t cycle;
|
||||
};
|
||||
|
||||
/* [on_process] */
|
||||
|
|
@ -41,9 +43,11 @@ static void on_process(void *userdata) {
|
|||
n_frames = SPA_MIN(b->requested, n_frames);
|
||||
|
||||
for (i = 0; i < n_frames; i++) {
|
||||
data->accumulator += M_PI_M2 * 440 / DEFAULT_RATE;
|
||||
if (data->accumulator >= M_PI_M2)
|
||||
data->accumulator += M_PI_M2 * DEFAULT_FREQ / DEFAULT_RATE; // * 440
|
||||
if (data->accumulator >= M_PI_M2) {
|
||||
data->accumulator -= M_PI_M2;
|
||||
data->cycle++;
|
||||
}
|
||||
|
||||
/* sin() gives a value between -1.0 and 1.0, we first apply
|
||||
* the volume and then scale with 32767.0 to get a 16 bits value
|
||||
|
|
@ -98,11 +102,13 @@ int main(int argc, char *argv[]) {
|
|||
PW_STREAM_FLAG_RT_PROCESS,
|
||||
params, 1);
|
||||
|
||||
// TODO: use pw_thread_loop instead of pw_main_loop
|
||||
pw_main_loop_run(data.loop);
|
||||
|
||||
printf("exitting\n");
|
||||
pw_stream_destroy(data.stream);
|
||||
pw_main_loop_destroy(data.loop);
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
/* [code] */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue