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_RATE 44100
|
||||||
#define DEFAULT_CHANNELS 2
|
#define DEFAULT_CHANNELS 2
|
||||||
#define DEFAULT_VOLUME 0.7
|
#define DEFAULT_VOLUME 0.7
|
||||||
|
#define DEFAULT_FREQ 200
|
||||||
|
|
||||||
#define PWSTREAM_NAME "Dorne"
|
#define PWSTREAM_NAME "Dorne"
|
||||||
|
|
||||||
|
|
@ -16,6 +17,7 @@ struct data {
|
||||||
struct pw_main_loop *loop;
|
struct pw_main_loop *loop;
|
||||||
struct pw_stream *stream;
|
struct pw_stream *stream;
|
||||||
double accumulator;
|
double accumulator;
|
||||||
|
uint32_t cycle;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* [on_process] */
|
/* [on_process] */
|
||||||
|
|
@ -41,9 +43,11 @@ static void on_process(void *userdata) {
|
||||||
n_frames = SPA_MIN(b->requested, n_frames);
|
n_frames = SPA_MIN(b->requested, n_frames);
|
||||||
|
|
||||||
for (i = 0; i < n_frames; i++) {
|
for (i = 0; i < n_frames; i++) {
|
||||||
data->accumulator += M_PI_M2 * 440 / DEFAULT_RATE;
|
data->accumulator += M_PI_M2 * DEFAULT_FREQ / DEFAULT_RATE; // * 440
|
||||||
if (data->accumulator >= M_PI_M2)
|
if (data->accumulator >= M_PI_M2) {
|
||||||
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
|
/* 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
|
* 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,
|
PW_STREAM_FLAG_RT_PROCESS,
|
||||||
params, 1);
|
params, 1);
|
||||||
|
|
||||||
|
// TODO: use pw_thread_loop instead of pw_main_loop
|
||||||
pw_main_loop_run(data.loop);
|
pw_main_loop_run(data.loop);
|
||||||
|
|
||||||
|
printf("exitting\n");
|
||||||
pw_stream_destroy(data.stream);
|
pw_stream_destroy(data.stream);
|
||||||
pw_main_loop_destroy(data.loop);
|
pw_main_loop_destroy(data.loop);
|
||||||
|
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
/* [code] */
|
/* [code] */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue