arm: vf610: fix double iomux configuration for vf610twr board
[u-boot/qq2440-u-boot.git] / drivers / sound / sound.c
blob9dda2dba822aa8bc0a4aaf504130f1bfaddfc530
1 /*
2 * Copyright (C) 2012 Samsung Electronics
3 * R. Chandrasekar <rcsekar@samsung.com>
5 * SPDX-License-Identifier: GPL-2.0+
6 */
8 #include <common.h>
9 #include <sound.h>
11 void sound_create_square_wave(unsigned short *data, int size, uint32_t freq)
13 const int sample = 48000;
14 const unsigned short amplitude = 16000; /* between 1 and 32767 */
15 const int period = freq ? sample / freq : 0;
16 const int half = period / 2;
18 assert(freq);
20 /* Make sure we don't overflow our buffer */
21 if (size % 2)
22 size--;
24 while (size) {
25 int i;
26 for (i = 0; size && i < half; i++) {
27 size -= 2;
28 *data++ = amplitude;
29 *data++ = amplitude;
31 for (i = 0; size && i < period - half; i++) {
32 size -= 2;
33 *data++ = -amplitude;
34 *data++ = -amplitude;