grok-3-mini-beta· xAI
LMArena Human Preference 140K
c99 linux craft smallest possible 4bits audio synthesizer, with alsa.
- User
c99 linux craft smallest possible 4bits audio synthesizer, with alsa.
- Assistant
#include <alsa/asoundlib.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #define M_PI 3.14159265358979323846 int main() { snd_pcm_t *handle; if (snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0) < 0) return 1; snd_pcm_hw_params_t *params; snd_pcm_hw_params_malloc(¶ms); snd_pcm_hw_params_any(handle, params); snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED); snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_U8); snd_pcm_hw_params_set_channels(handle, params, 1); unsigned int rate = 44100; snd_pcm_hw_params_set_rate_near(handle, params, &rate, 0); snd_pcm_hw_params(handle, params); snd_pcm_prepare(handle); const int samples = 4410; // ~0.1 second char buf[samples]; for(int i = 0; i < samples; i++) { double t = (double)i / rate; double sample = sin(2 * M_PI * 440 * t); // 440 Hz sine wave int quantized = (int)((sample + 1.0) / 2.0 * 15.0); // Quantize to 0-15 if(quantized < 0) quantized = 0; if(quantized > 15) quantized = 15; buf[i] = (char)(quantized * 17); // Scale to 0-255 for U8 } snd_pcm_writei(handle, buf, samples); snd_pcm_drain(handle); snd_pcm_close(handle); snd_pcm_hw_params_free(params); return 0; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.