separate frequency from accumulator
This commit is contained in:
parent
df5b2e9b5c
commit
2711027dcf
1 changed files with 8 additions and 5 deletions
13
lib/main.c
13
lib/main.c
|
|
@ -11,6 +11,8 @@
|
|||
#define DEFAULT_VOLUME 0.7
|
||||
#define DEFAULT_FREQ 200
|
||||
|
||||
#define DEFAULT_ACCUMULATOR -1
|
||||
|
||||
#define PWSTREAM_NAME "Dorne"
|
||||
|
||||
struct data {
|
||||
|
|
@ -43,9 +45,9 @@ 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 * DEFAULT_FREQ / DEFAULT_RATE; // * 440
|
||||
if (data->accumulator >= M_PI_M2) {
|
||||
data->accumulator -= M_PI_M2;
|
||||
// data->accumulator += M_PI_M2 * DEFAULT_FREQ / DEFAULT_RATE; // * 440
|
||||
if (data->accumulator++ == DEFAULT_RATE) {
|
||||
data->accumulator = DEFAULT_ACCUMULATOR;
|
||||
data->cycle++;
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +57,7 @@ static void on_process(void *userdata) {
|
|||
* Another common method to convert a double to
|
||||
* 16 bits is to multiple by 32768.0 and then clamp to
|
||||
* [-32768 32767] to get the full 16 bits range. */
|
||||
val = sin(data->accumulator) * DEFAULT_VOLUME * 32767.0;
|
||||
val = sin(data->accumulator * M_PI_M2 * DEFAULT_FREQ / DEFAULT_RATE) * DEFAULT_VOLUME * 32767.0;
|
||||
for (c = 0; c < DEFAULT_CHANNELS; c++)
|
||||
*dst++ = val;
|
||||
}
|
||||
|
|
@ -75,7 +77,8 @@ static const struct pw_stream_events stream_events = {
|
|||
|
||||
int main(int argc, char *argv[]) {
|
||||
struct data data = {
|
||||
0,
|
||||
.accumulator = DEFAULT_ACCUMULATOR,
|
||||
.cycle = 0,
|
||||
};
|
||||
const struct spa_pod *params[1];
|
||||
uint8_t buffer[1024];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue