yue

Programmatic music library

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
(use-modules (ice-9 binary-ports))
(include "music.scm")

(define bitrate 8000)

; Get the music as a list sampled at the bitrate
(define (play t) (
	cons (music t) (if (< t 30)
		(play (+ t (/ 1 bitrate)))
		'()
	)
))

; Output the list in the s16 raw audio format
(for-each (lambda (a) (
	let ((b (modulo (inexact->exact (round (* (+ a 2) 32768))) 65536)))
		cons
			(put-u8 (current-output-port) (modulo b 256))
			(put-u8 (current-output-port) (quotient b 256))
)) (play 0))