home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / sun / volume2 / ss1-music < prev    next >
Text File  |  1990-02-05  |  11KB  |  679 lines

  1. Path: uunet!cs.utexas.edu!yale!cmcl2!rutgers!aramis.rutgers.edu!dartagnan.rutgers.edu!mcgrew
  2. From: mcgrew@dartagnan.rutgers.edu (Charles Mcgrew)
  3. Newsgroups: comp.sources.sun
  4. Subject: v02i010:  Music player for SS1s
  5. Message-ID: <Feb.5.14.59.24.1990.17302@dartagnan.rutgers.edu>
  6. Date: 5 Feb 90 19:59:27 GMT
  7. Organization: Rutgers Univ., New Brunswick, N.J.
  8. Lines: 668
  9. Approved: mcgrew@aramis.rutgers.edu
  10.  
  11. Submitted-by: ttl@astroatc.uucp (Tony Laundrie)
  12. Posting-number: Volume 2, Issue 10
  13. Archive-name: ss1-music
  14.  
  15.  
  16. Here is a brief audio program that I wrote for generating music on the SUN
  17. SPARCstation audio device.  If you make any changes or improvements, please
  18. send them to me, ...uwvax!astroatc!ttl  or  ttl@astroatc.UUCP
  19.  
  20. After unwrapping and Making the executable "beep", you can play a song
  21. by typing "beep < soundfile".  Several soundfiles (dixie, growforme, suddenly,
  22. and jingle) are included.  Have fun!
  23.  
  24.  
  25. [ Typing in tunes for this program to play is pretty easy -- I typed
  26. in the first two pages from "here comes the sun" in about 45 minutes
  27. (that includes 'learning-curve' time)...  I'd like to keep an archive
  28. of music people write, so send them in!  Music files will be kept in
  29. src/sun-sources/music in the anonymous ftp location of rutgers.edu.
  30. Also, the first batch of sparc-playable sounds has arrived, and is in
  31. src/sun-sources/sounds.  See src/sun-sources/README for more info. -CWM]
  32.  
  33.  
  34. # This is a shell archive.  Remove anything before this line,
  35. # then unpack it by saving it in a file and typing "sh file".
  36. #
  37.  
  38. echo x - Makefile
  39. sed 's/^@//' > "Makefile" <<'@//E*O*F Makefile//'
  40.  
  41. beep:    beep.c
  42.     cc -O -o beep beep.c
  43. @//E*O*F Makefile//
  44. chmod u=rw,g=r,o=r Makefile
  45.  
  46. echo x - README
  47. sed 's/^@//' > "README" <<'@//E*O*F README//'
  48. For music files used with the beep program,
  49.  
  50. The first line is:
  51. RATE (low = fast), PITCH (low = low), VOLUME (low = quiet), DECAY (0 = no decay)
  52.  
  53. Floating point numbers accepted for RATE, VOLUME, and DECAY.
  54.  
  55. All other lines represent notes and rests, as follows:
  56.  
  57. VOL BEATS NOTE WORD
  58.  
  59. VOL and BEATS must be integers.
  60.  
  61. VOL is multiplied by first line VOLUME to get note's volume (range = 0-255).
  62. Use VOL = 0 for a rest.
  63.  
  64. BEATS is multiplied by first line RATE to get note's length (units = 1/32 sec).
  65. Result should be an integer.
  66.  
  67. NOTE consists of an octave (0-8) concatenated with a note (a-g) concatenated
  68. with a flat or sharp (b or #).  Badly-formed notes are not detected.
  69.  
  70. The word is printed to standard output.
  71. Words suffixed with - don't have a space automatically printed after them.
  72. Words suffixed with \ have a newline appended.
  73.  
  74.  
  75.  
  76. See "growforme" for an example.
  77. @//E*O*F README//
  78. chmod u=rw,g=r,o=r README
  79.  
  80. echo x - beep.c
  81. sed 's/^@//' > "beep.c" <<'@//E*O*F beep.c//'
  82. #include <stdio.h>
  83. #include <fcntl.h>
  84. #include <sys/ioctl.h>
  85. #include <sun/audioio.h>
  86. #define BUFLEN 256
  87.  
  88. static int notes[9][12] = {
  89.    { 1002, 946, 893, 843, 795, 751, 709, 669, 631, 596, 562, 531 },
  90.    {  501, 473, 446, 421, 398, 375, 354, 334, 316, 298, 281, 265 },
  91.    {  250, 236, 223, 211, 199, 188, 177, 167, 158, 149, 141, 133 },
  92.    {  125, 118, 112, 105,  99,  94,  89,  84,  79,  74,  70,  66 },
  93.    {   63,  59,  56,  53,  50,  47,  44,  42,  39,  37,  35,  33 },
  94.    {   31,  30,  28,  26,  25,  23,  22,  21,  20,  19,  18,  17 },
  95.    {   16,  15,  14,  13,  12,  11,  11,  10,  10,   9,   9,   8 },
  96.    {    7,   7,   7,   7,   6,   6,   6,   5,   5,   5,   4,   4 },
  97.    {    4,   4,   3,   3,   3,   3,   3,   3,   2,   2,   2,   2 }
  98. };
  99.  
  100. static int conv[7] = {9, 11, 0, 2, 4, 5, 7};
  101.  
  102. int oct, n, length, f, period, j, i, k;
  103. float speed, loudness, volume, decay;
  104. int tone;
  105. char buf[BUFLEN];
  106. char mess[80], *p;
  107.  
  108. main (argc, argv)
  109. int argc;
  110. char *argv[];
  111. {
  112.    f = open ("/dev/audio", O_WRONLY);
  113.    scanf ("%f %d %f %f", &speed, &tone, &loudness, &decay);
  114. CONT:
  115.    do {
  116.       ioctl (f, AUDIOWRITEQ, &n);
  117.    } while (n);
  118.    if (gets (mess) == NULL) exit (0);
  119.    if (sscanf (mess, "%f%d%s%s", &volume, &length, buf, mess) == 4) {
  120.       n = strlen(mess);
  121.       if (mess[n-1] == '-') {
  122.      mess[n-1] = '\0';
  123.      fputs (mess, stdout);
  124.       }
  125.       else if (mess[n-1] == '\\') {
  126.      mess[n-1] = '\0';
  127.      fputs (mess, stdout);
  128.      putchar ('\n');
  129.       }
  130.       else {
  131.      fputs (mess, stdout);
  132.      putchar (' ');
  133.       }
  134.       fflush (stdout);
  135.    }
  136.    volume = loudness * volume;
  137.    length = (int) (speed * length);
  138.    oct = buf[0] - '0';
  139.    n = conv[buf[1] - 'a'];
  140.    if (buf[2] == 'b') --n;
  141.    else if (buf[2] == '#') ++n;
  142.    n = n + tone;
  143.    period = notes[oct][n];
  144.  
  145.    i = 0;
  146.    k = 0;
  147.    for (;;) {
  148.       for (j = 0; j < period>>1; ++j) {
  149.      buf[i++] = 0;
  150.      if ((volume = volume - decay) < 0.0) volume = 0.0;
  151.      if (i >= BUFLEN) {
  152.         write (f,buf,BUFLEN);
  153.         if (++k >= length) goto CONT;
  154.         i = 0;
  155.      }
  156.       }
  157.       for (j = 0; j < ((period>>1) + (period & 0x1)); ++j) {
  158.      buf[i++] = (int) volume;
  159.      if ((volume = volume - decay) < 0.0) volume = 0.0;
  160.      if (i >= BUFLEN) {
  161.         write (f,buf,BUFLEN);
  162.         if (++k >= length) goto CONT;
  163.         i = 0;
  164.      }
  165.       }
  166.    }
  167. }
  168. @//E*O*F beep.c//
  169. chmod u=rw,g=r,o=r beep.c
  170.  
  171. echo x - dixie
  172. sed 's/^@//' > "dixie" <<'@//E*O*F dixie//'
  173. 0.8 0 127 0.44
  174. 2 4 5g
  175. 2 4 5e
  176. 2 4 5c
  177. 0 4 0c
  178. 2 4 5c
  179. 0 4 0c
  180. 2 4 5c
  181. 2 4 5d
  182. 2 4 5e
  183. 2 4 5f
  184. 2 4 5g
  185. 0 4 0c
  186. 2 4 5g
  187. 0 4 0c
  188. 2 4 5g
  189. 0 4 0c
  190. 2 4 5e
  191. @//E*O*F dixie//
  192. chmod u=rw,g=r,o=r dixie
  193.  
  194. echo x - growforme
  195. sed 's/^@//' > "growforme" <<'@//E*O*F growforme//'
  196. 1 12 255 0
  197. 0 35 0c
  198. 1 6 2bb I've
  199. 0 1 0c 
  200. 1 6 2bb gi-
  201. 0 1 0c 
  202. 1 6 3eb ven
  203. 0 1 0c 
  204. 1 6 3f you
  205. 0 1 0c 
  206. 1 13 3g sun-
  207. 0 1 0c 
  208. 1 28 3eb shine,\
  209. 0 14 0c 
  210. 1 6 2bb I've
  211. 0 1 0c 
  212. 1 6 2bb gi-
  213. 0 1 0c 
  214. 1 6 3eb ven
  215. 0 1 0c 
  216. 1 6 3g you
  217. 0 1 0c 
  218. 1 21 3bb dirt,\
  219. 0 35 0c 
  220. 1 6 3eb You've
  221. 0 1 0c 
  222. 1 6 3eb gi-
  223. 0 1 0c 
  224. 1 6 3ab ven
  225. 0 1 0c 
  226. 1 6 3bb me
  227. 0 1 0c 
  228. 1 6 4c noth-
  229. 0 1 0c 
  230. 1 6 3bb 
  231. 0 1 0c 
  232. 1 28 3ab in',\
  233. 0 14 0c 
  234. 1 6 3eb But
  235. 0 1 0c 
  236. 1 6 3eb heart-
  237. 0 1 0c 
  238. 1 6 3ab ache
  239. 0 1 0c 
  240. 1 6 4c and
  241. 0 1 0c 
  242. 1 21 4eb hurt.\
  243. 0 35 0c 
  244. 1 6 4eb I'm
  245. 0 1 0c 
  246. 1 6 4eb beg-
  247. 0 1 0c 
  248. 1 6 4d gin'
  249. 0 1 0c 
  250. 1 6 4c you
  251. 0 1 0c 
  252. 1 13 3bb sweet-
  253. 0 1 0c 
  254. 1 28 3g ly,\
  255. 0 14 0c 
  256. 1 6 3eb I'm
  257. 0 1 0c 
  258. 1 6 3eb down
  259. 0 1 0c 
  260. 1 6 3f on
  261. 0 1 0c 
  262. 1 6 3g my
  263. 0 1 0c 
  264. 1 42 3ab knees,\
  265. 0 28 0c 
  266. 1 13 4cb Oh
  267. 0 1 0c 
  268. 1 42 4c please,
  269. 0 14 0c 
  270. 1 13 4d grow
  271. 0 1 0c 
  272. 1 13 4d for
  273. 0 1 0c 
  274. 1 21 4eb me!\
  275. 0 35 0c \
  276. 1 6 3eb I've
  277. 0 1 0c 
  278. 1 6 3eb gi-
  279. 0 1 0c 
  280. 1 6 3f ven
  281. 0 1 0c 
  282. 1 6 3g you
  283. 0 1 0c 
  284. 1 13 3g south-
  285. 0 1 0c 
  286. 1 20 3e ern
  287. 0 1 0c 
  288. 1 6 3f ex-
  289. 0 1 0c 
  290. 1 13 3g po-
  291. 0 1 0c 
  292. 1 20 3ab sure
  293. 0 1 0c 
  294. 1 6 3bb to
  295. 0 1 0c 
  296. 1 6 3bb get
  297. 0 1 0c 
  298. 1 6 3ab you
  299. 0 1 0c 
  300. 1 6 3g to
  301. 0 1 0c 
  302. 1 21 3ab thrive,\
  303. 0 14 0c 
  304. 1 6 3f I've
  305. 0 1 0c 
  306. 1 6 3f pinched
  307. 0 1 0c 
  308. 1 6 3g you
  309. 0 1 0c 
  310. 1 6 3ab back
  311. 0 1 0c 
  312. 1 13 3a hard
  313. 0 1 0c 
  314. 1 13 3f# like
  315. 0 1 0c 
  316. 1 13 3g I'm
  317. 0 1 0c 
  318. 1 13 3a s'posed
  319. 0 1 0c 
  320. 1 13 3bb ta,
  321. 0 1 0c 
  322. 1 13 4c you're
  323. 0 1 0c 
  324. 1 13 4c bare-
  325. 0 1 0c 
  326. 1 13 3bb ly
  327. 0 1 0c 
  328. 1 13 3a a-
  329. 0 1 0c 
  330. 1 13 3bb live,\
  331. 0 1 0c 
  332. 1 6 3eb I've
  333. 0 1 0c 
  334. 1 6 3eb tried
  335. 0 1 0c 
  336. 1 6 3ab you
  337. 0 1 0c 
  338. 1 6 3bb at
  339. 0 1 0c 
  340. 1 13 4c lev-
  341. 0 1 0c 
  342. 1 13 3ab els
  343. 0 1 0c 
  344. 1 13 3bb of
  345. 0 1 0c 
  346. 1 13 4c mois-
  347. 0 1 0c 
  348. 1 6 4d ture
  349. 0 1 0c 
  350. 0 13 0c 
  351. 0 1 0c 
  352. 1 6 4c from
  353. 0 1 0c 
  354. 1 13 3bb des-
  355. 0 1 0c 
  356. 1 13 4c ert
  357. 0 1 0c 
  358. 1 13 4d to
  359. 0 1 0c 
  360. 1 21 4eb mud,\
  361. 0 14 0c 
  362. 1 6 4eb I've
  363. 0 1 0c 
  364. 1 6 4eb gi-
  365. 0 1 0c 
  366. 1 6 4eb ven
  367. 0 1 0c 
  368. 1 6 4eb you
  369. 0 1 0c 
  370. 1 6 4eb grow
  371. 0 1 0c 
  372. 1 6 4eb lights
  373. 0 1 0c 
  374. 1 6 4eb and
  375. 0 1 0c 
  376. 1 6 4eb min-
  377. 0 1 0c 
  378. 1 6 4eb er-
  379. 0 1 0c 
  380. 1 6 4eb al
  381. 0 1 0c 
  382. 1 6 4eb sup-
  383. 0 1 0c 
  384. 1 6 4d ple-
  385. 0 1 0c 
  386. 1 6 4c ments,\
  387. 0 1 0c 
  388. 1 6 4d What
  389. 0 1 0c 
  390. 1 6 4d do
  391. 0 1 0c 
  392. 1 6 4d you
  393. 0 1 0c 
  394. 1 6 4d want
  395. 0 1 0c 
  396. 1 6 4eb from
  397. 0 1 0c 
  398. 1 6 4e me?
  399. 0 1 0c 
  400. 1 7 4f Blood?!\
  401. 0 7 0c \
  402. 1 6 2bb I've
  403. 0 1 0c 
  404. 1 6 2bb gi-
  405. 0 1 0c 
  406. 1 6 3eb ven
  407. 0 1 0c 
  408. 1 6 3f you
  409. 0 1 0c 
  410. 1 13 3g sun-
  411. 0 1 0c 
  412. 1 28 3eb light,\
  413. 0 14 0c 
  414. 1 6 2bb I've
  415. 0 1 0c 
  416. 1 6 2bb gi-
  417. 0 1 0c 
  418. 1 6 3eb ven
  419. 0 1 0c 
  420. 1 6 3g you
  421. 0 1 0c 
  422. 1 21 3bb rain,\
  423. 0 35 0c 
  424. 1 6 3eb Looks
  425. 0 1 0c 
  426. 1 6 3eb like
  427. 0 1 0c 
  428. 1 6 3ab you're
  429. 0 1 0c 
  430. 1 6 3bb not
  431. 0 1 0c 
  432. 1 6 4c hap-
  433. 0 1 0c 
  434. 1 6 3bb 
  435. 0 1 0c 
  436. 1 28 3ab py,\
  437. 0 7 0c 
  438. 1 6 3eb 'Less
  439. 0 1 0c 
  440. 1 6 3eb I
  441. 0 1 0c 
  442. 1 6 3eb o-
  443. 0 1 0c 
  444. 1 6 3ab pen
  445. 0 1 0c 
  446. 1 6 4c a
  447. 0 1 0c 
  448. 1 49 4eb vein,\
  449. 0 7 0c 
  450. 1 6 4eb I'll
  451. 0 1 0c 
  452. 1 6 4eb give
  453. 0 1 0c 
  454. 1 6 4d you
  455. 0 1 0c 
  456. 1 6 4c a
  457. 0 1 0c 
  458. 1 6 3bb few
  459. 0 1 0c 
  460. 1 14 3g drops,\
  461. 0 35 0c 
  462. 1 6 3eb If
  463. 0 1 0c 
  464. 1 6 3eb that-
  465. 0 1 0c 
  466. 1 6 3f 'll
  467. 0 1 0c 
  468. 1 6 3g ap-
  469. 0 1 0c 
  470. 1 21 3ab pease,\
  471. 0 42 0c 
  472. 1 20 4cb Now
  473. 0 1 0c 
  474. 1 42 4c please,
  475. 0 28 0c 
  476. 1 13 4c oh
  477. 0 1 0c 
  478. 1 41 4d please,
  479. 0 1 0c 
  480. 1 20 4c grow
  481. 0 1 0c 
  482. 1 20 3bb for
  483. 0 1 0c 
  484. 1 301 4eb me!\
  485. 0 35 0c
  486. @//E*O*F growforme//
  487. chmod u=rw,g=r,o=r growforme
  488.  
  489. echo x - jingle
  490. sed 's/^@//' > "jingle" <<'@//E*O*F jingle//'
  491. 4 0 127 0
  492. 1 1 4c
  493. 1 3 4f
  494. 1 1 4e
  495. 1 2 4f
  496. 1 2 4a
  497. 1 3 4g
  498. 1 1 4f
  499. 1 2 4g
  500. @//E*O*F jingle//
  501. chmod u=rw,g=r,o=r jingle
  502.  
  503. echo x - suddenly
  504. sed 's/^@//' > "suddenly" <<'@//E*O*F suddenly//'
  505. 1 12 255 0
  506. 0 25 0c
  507. 1 9 3d Lift
  508. 0 1 0c 
  509. 1 9 3e up
  510. 0 1 0c 
  511. 1 9 3f# your
  512. 0 1 0c 
  513. 1 20 3e head,\
  514. 0 20 0c 
  515. 1 9 2a Wash
  516. 0 1 0c 
  517. 1 9 3d off
  518. 0 1 0c 
  519. 1 9 3e your
  520. 0 1 0c 
  521. 1 9 3f# mas-
  522. 0 1 0c 
  523. 1 19 3e ca-
  524. 0 1 0c 
  525. 1 10 2a ra,\
  526. 0 20 0c 
  527. 1 9 3f# Here,
  528. 0 1 0c 
  529. 1 9 3g# take
  530. 0 1 0c 
  531. 1 9 3a my
  532. 0 1 0c 
  533. 1 19 3a Klee-
  534. 0 1 0c 
  535. 1 9 2a nex,\
  536. 0 1 0c 
  537. 1 9 2a Wipe
  538. 0 1 0c 
  539. 1 9 3c# that
  540. 0 1 0c 
  541. 1 9 3d lip-
  542. 0 1 0c 
  543. 1 9 3c# stick
  544. 0 1 0c 
  545. 1 9 2b a-
  546. 0 1 0c 
  547. 1 20 3c# way,\
  548. 0 30 0c \
  549. 1 9 3d Show
  550. 0 1 0c 
  551. 1 9 3e me
  552. 0 1 0c 
  553. 1 9 3f# your
  554. 0 1 0c 
  555. 1 20 3e face,\
  556. 0 30 0c 
  557. 1 9 3d Clean
  558. 0 1 0c 
  559. 1 9 3e as
  560. 0 1 0c 
  561. 1 9 3f# the
  562. 0 1 0c 
  563. 1 19 3e mor-
  564. 0 1 0c 
  565. 1 10 2a nin',\
  566. 0 15 0c 
  567. 1 4 2a I
  568. 0 1 0c 
  569. 1 9 3f# know
  570. 0 1 0c 
  571. 1 9 3g# things
  572. 0 1 0c 
  573. 1 9 3a were
  574. 0 1 0c 
  575. 1 20 3a bad,\
  576. 0 25 0c 
  577. 1 4 3e But
  578. 0 1 0c 
  579. 1 14 3e now
  580. 0 1 0c 
  581. 1 14 3a they're
  582. 0 1 0c 
  583. 1 9 3g# o-
  584. 0 1 0c 
  585. 1 60 3a kay,\
  586. 0 60 0c \
  587. 1 14 4c# Sud-
  588. 0 1 0c 
  589. 1 14 3b den-
  590. 0 1 0c 
  591. 1 9 3a ly
  592. 0 1 0c 
  593. 1 29 3a Sey-
  594. 0 1 0c 
  595. 1 50 3f# mour
  596. 0 30 0c 
  597. 1 9 3f# is
  598. 0 1 0c 
  599. 1 14 3f# stand-
  600. 0 1 0c 
  601. 1 14 3g# in'
  602. 0 1 0c 
  603. 1 9 3a be-
  604. 0 1 0c 
  605. 1 29 3e side
  606. 0 1 0c 
  607. 1 50 3c# you,\
  608. 0 30 0c 
  609. 1 9 3c# You
  610. 0 1 0c 
  611. 1 14 4c# don't
  612. 0 1 0c 
  613. 1 14 3b need
  614. 0 1 0c 
  615. 1 9 3a no
  616. 0 1 0c 
  617. 1 29 3b make-
  618. 0 1 0c 
  619. 1 50 3g# up,
  620. 0 30 0c 
  621. 1 9 3e don't
  622. 0 1 0c 
  623. 1 14 3f# have
  624. 0 1 0c 
  625. 1 14 3a to
  626. 0 1 0c 
  627. 1 9 3b pre-
  628. 0 1 0c 
  629. 1 119 4c# tend,\
  630. 0 1 0c 
  631. 1 14 4c# Sud-
  632. 0 1 0c 
  633. 1 14 3b den-
  634. 0 1 0c 
  635. 1 9 3a ly
  636. 0 1 0c 
  637. 1 29 3a Sey-
  638. 0 1 0c 
  639. 1 50 3f# mour
  640. 0 30 0c 
  641. 1 9 3f# is
  642. 0 1 0c 
  643. 1 14 3f# here
  644. 0 1 0c 
  645. 1 14 3g# to
  646. 0 1 0c 
  647. 1 9 3a pro-
  648. 0 1 0c 
  649. 1 39 3e vide
  650. 0 1 0c 
  651. 1 40 3a you,\
  652. 0 40 0c 
  653. 1 14 3f# Sweet
  654. 0 1 0c 
  655. 1 14 3g# un-
  656. 0 1 0c 
  657. 1 9 3a der-
  658. 0 1 0c 
  659. 1 24 4c# stand-
  660. 0 1 0c 
  661. 1 4 3b 
  662. 0 1 0c 
  663. 1 9 3a 
  664. 0 1 0c 
  665. 1 40 3a ing,
  666. 0 40 0c 
  667. 1 14 3e Sey-
  668. 0 1 0c 
  669. 1 14 3a mour's
  670. 0 1 0c 
  671. 1 9 3g# your
  672. 0 1 0c 
  673. 1 40 3a friend.\
  674. 0 25 0c
  675. @//E*O*F suddenly//
  676. chmod u=rw,g=r,o=r suddenly
  677.  
  678. exit 0
  679.