Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | sdl2.c: Snatch LD beep code; we have beeps .. beep beep. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | ams/sdl |
Files: | files | file ages | folders |
SHA3-256: |
baee42c6958152fdeee679afe202a6c1 |
User & Date: | ams 2024-06-18 11:02:33 |
Context
2024-06-18
| ||
11:32 | Makefile: Link to -lm. check-in: f357f0c422 user: ams tags: ams/sdl | |
11:02 | sdl2.c: Snatch LD beep code; we have beeps .. beep beep. check-in: baee42c695 user: ams tags: ams/sdl | |
09:02 | Start adding boiler plate to implement %BEEP. check-in: b24e6a0b4b user: ams tags: ams/sdl | |
Changes
Changes to iob.c.
︙ | ︙ | |||
69 70 71 72 73 74 75 | // MMcM: It's the number of microseconds between triggers of the // flip-flop. That is, half the wavelength. So the frequency is, I // think, (/ 1e6 (* #o1350 2)). So I guess 672Hz. And duration is // only .13sec. #if WITH_X11 x11_beep(); #elif WITH_SDL2 | | | 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | // MMcM: It's the number of microseconds between triggers of the // flip-flop. That is, half the wavelength. So the frequency is, I // think, (/ 1e6 (* #o1350 2)). So I guess 672Hz. And duration is // only .13sec. #if WITH_X11 x11_beep(); #elif WITH_SDL2 sdl2_beep(-1); #else fprintf(stderr, "\a"); /* Beep! */ #endif break; case 0112: *pv = iob_csr; INFO(TRACE_IOB | TRACE_UNIBUS, "unibus: kbd csr %011o\n", *pv); |
︙ | ︙ | |||
153 154 155 156 157 158 159 | * Triggered via %BEEP. */ #if WITH_X11 x11_beep(); #elif WITH_SDL1 sdl1_beep(); #elif WITH_SDL2 | | | 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | * Triggered via %BEEP. */ #if WITH_X11 x11_beep(); #elif WITH_SDL1 sdl1_beep(); #elif WITH_SDL2 sdl2_beep(v); #else fprintf(stderr, "\a"); /* Beep! */ #endif break; case 0112: INFO(TRACE_IOB | TRACE_UNIBUS, "unibus: kbd csr\n"); iob_csr = (iob_csr & ~017) | (v & 017); |
︙ | ︙ |
Changes to sdl2.c.
︙ | ︙ | |||
257 258 259 260 261 262 263 | break; case SDL_QUIT: exit(0); break; } } } | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > | > < | 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | break; case SDL_QUIT: exit(0); break; } } } float xbeep_volume = 1.0f; int AMPLITUDE = 28000; const int SAMPLE_RATE = 44100; int xbeep_sample_nr = 0; float xbeep_freq = 0.0f; void xbeep_audio_callback(void *user_data, Uint8 *raw_buffer, int bytes) { Sint16 *buffer = (Sint16*)raw_buffer; int length = bytes / 2; // 2 bytes per sample for AUDIO_S16SYS float *freq = (float *)(user_data); int amp = AMPLITUDE * xbeep_volume; for(int i = 0; i < length; i++, xbeep_sample_nr++) { double time = (double)xbeep_sample_nr / (double)SAMPLE_RATE; buffer[i] = (Sint16)(amp * sin(2.0f * M_PI * (*freq) * time)); // render sine wave } } void xbeep_audio_init() { SDL_AudioSpec want; SDL_AudioSpec have; want.freq = SAMPLE_RATE; want.format = AUDIO_S16SYS; want.channels = 1; want.samples = 2048; want.callback = xbeep_audio_callback; want.userdata = &xbeep_freq; if(SDL_OpenAudio(&want, &have) != 0) SDL_LogError(SDL_LOG_CATEGORY_AUDIO, "Failed to open audio: %s", SDL_GetError()); if(want.format != have.format) SDL_LogError(SDL_LOG_CATEGORY_AUDIO, "Failed to get the desired AudioSpec"); SDL_PauseAudio(1); } void xbeep_audio_close() { SDL_CloseAudio(); } void xbeep(int halfwavelength, int duration) { xbeep_freq = 1000000.0f / (float)(halfwavelength*2); xbeep_sample_nr = 0; SDL_PauseAudio(0); SDL_Delay(duration/1000); SDL_PauseAudio(1); } void sdl2_beep(int v) { ///XBEEP (MISC-INST-ENTRY %BEEP) ///;;; First argument is half-wavelength, second is duration. Both are in microseconds. ///;;; M-1 has 2nd argument (duration) which is added to initial time-check ///;;; M-2 contains most recent time check ///;;; to compute quitting time ///;;; M-C contains 1st argument, the wavelength ///;;; M-4 contains the time at which the next click must be done. ///;;; Note that the 32-bit clock wraps around once an hour, we have to be careful ///;;; to compare clock values in the correct way, namely without overflow checking. extern uint32_t mmem[32]; #define DTP_FIX_VAL(x) ((x) & ((1 << 24) - 1)) #define DTP_FIX(x) (DTP_FIX_VAL(x) | 5 << 25) int wavelength = DTP_FIX_VAL(mmem[7]);//M-C M-MEM 7 int duration = DTP_FIX_VAL(mmem[22]);//M-1 M-MEM 22 xbeep(wavelength, duration); } void sdl2_init(void) { NOTICE(TRACE_USIM, "tv: using SDL backend for monitor and keyboard\n"); Foreground = 0xffffff; // White Background = 0x000000; // Black xbeep_audio_init(); SDL_CreateWindowAndRenderer(tv_width, tv_height, SDL_WINDOW_OPENGL, &window, &renderer); SDL_ShowCursor(0); /* Invisible cursor. */ // SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); // SDL_RenderClear(renderer); // SDL_RenderPresent(renderer); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); // make the scaled rendering look smoother. |
︙ | ︙ |