1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
/**
* @ingroup sc68_lib
* @file sc68/sc68.h
* @author Benjamin Gerard
* @date 2003/08/07
* @brief sc68 API header.
*
*/
/* Copyright (C) 1998-2011 Benjamin Gerard */
/* Building */
/* Using */
/**
* @defgroup sc68_lib sc68 library
* @ingroup api68
*
* This API provides functions to use sc68 libraries efficiently.
*
* @par Multi-threading concern
*
* sc68 should now be thread safe. At least concerning the functions
* with a sc68_t parameter. As no torture test has been run against
* it this should be considered as quiet experimental.
*
* @par Quick start
*
* Here is a quiet minimalist piece of code to use basics of sc68
* library:
*
* @code
* #include <sc68/sc68.h>
* #include <FILE.h> // for fwrite()
*
* sc68_t * sc68 = 0;
* char buffer[512*4];
* int n;
*
* // Initialise the library.
* // You should consider using sc68_init_t struct.
* if (sc68_init(0)) goto error;
*
* // Create an emulator instance.
* // You should consider using sc68_create_t struct.
* if (sc68 = sc68_create(0), !sc68) goto error;
*
* // Load an sc68 file.
* if (sc68_load_url(sc68, fname)) {
* goto error;
* }
*
* // Set track and loop (optionnal).
* sc68_play(sc68, 1, 1);
*
* // Loop until the end of disk. You can use SC68_LOOP to wait the end
* // of the track. Notice that SC68_ERROR set all bits and make the loop
* // break too.
* while ( (n=sizeof(buffer)>>2), ! (sc68_process(sc68, buffer, &n) & SC68_END) ) {
* fwrite(buffer, 1, n, stdout); // copy PCM to stdout
* }
*
* // Close eject the current disk.
* sc68_close(sc68);
*
* error:
*
* // Destroy sc68 instance.
* sc68_destroy(sc68);
*
* // Shutdown sc68 library.
* sc68_shutdown();
*
* @endcode
*
* @{
*/
/**
* sc68 exported symbol.
*
* Define special atribut for exported symbol.
*
* - empty: static or classic .so library
* - __attribute__ (visibility("default"))): gcc support visibility.
* - __declspec(dllexport): creating a win32 DLL.
* - __declspec(dllimport): using a win32 DLL.
*/
/** API information. */
typedef struct _sc68_s sc68_t;
/** API disk. */
typedef void * sc68_disk_t;
/**
* Message function.
*
* @param cat @ref msg68_cat_e "message category"
* @param sc68 sc68 instance
* @param fmt printf like format string
* @param list variable argument list
* */
typedef void ;
/**
* API initialization parameters.
*
* The sc68_init_t must be properly filled before calling the
* sc68_init() function.
*
*/
typedef struct sc68_init_t;
/**
* Instance creation parameters.
*/
typedef struct sc68_create_t;
/**
* metatag struct.
* @warning MUST match the tag68_t struct defined in tag68.h.
*/
typedef struct sc68_tag_t;
/**
* Music common information.
*/
typedef struct sc68_cinfo_t;
/**
* Music information.
*/
typedef struct sc68_music_info_t;
/**
* Return code (as returned by sc68_process() function)
*/
;
/**
* sc68 sampling rate values in hertz (hz).
*/
;
/**
* @name API control functions.
* @{
*/
/**
* Get version number
*/
int ;
/**
* Get version string
*
*/
const char * ;
/**
* Initialise sc68 API.
*
* @param init Initialization parameters.
*
* @return error-code
* @retval 0 Success
* @retval -1 Error
*
* @see sc68_shutdown()
*/
int ;
/**
* Destroy sc68 API.
*
*/
void ;
/**
* Create sc68 instance.
*
* @param creation Creation parameters.
*
* @return Pointer to created sc68 instance.
* @retval 0 Error.
*
* @see sc68_destroy()
*/
sc68_t * ;
/**
* Destroy sc68 instance.
*
* @param sc68 sc68 instance to destroy.
*
* @see sc68_create()
* @note It is safe to call with null api.
*/
void ;
/**
* Get instance name.
*
* @param sc68 sc68 instance to destroy.
* @return sc68 instance name.
*/
const char * ;
/**
* Get user private data pointer.
*
* The sc68_cookie_ptr() function get a pointer to the user private
* data. This pointer can be use to get a modify this sc68 instance
* private data.
*
* @param sc68 sc68 instance.
* @return a pointer to the user data inside this sc68 instance.
* @retval 0 on error
*/
void ** ;
/**
* Set/Get sampling rate.
*
* @param sc68 sc68 api or 0 for library default.
* @param hz @ref sc68_spr_e "sampling rate" (in hz).
*
* @return Actual @ref sc68_spr_e "sampling rate"
* @retval -1 on error
* @retval >0 on success
*/
int ;
/**
* Set share data path.
*
* @param sc68 sc68 instance.
* @param path New shared data path.
*/
void ;
/**
* Set user data path.
*
* @param sc68 sc68 instance.
* @param path New user data path.
*/
void ;
/**
* Empty error message stack.
*
* @param sc68 sc68 instance or 0 for library messages.
*/
void ;
/**
* Pop and return last stacked error message.
*
* @param sc68 sc68 instance or 0 for library messages.
* @return Error string.
* @retval 0 No stacked error message.
*/
const char * ;
/**
* Stack an error Add Pop and return last stacked error message.
*
* @param sc68 sc68 instance or 0 for library messages.
* @return Error string.
* @retval 0 No stacked error message.
*/
int ;
/**
* Display debug message.
*
* @param sc68 sc68 instance.
* @param fmt printf() like format string.
*
* @see debugmsg68()
* @see sc68_t::debug_bit
*/
void ;
/**
* @}
*/
/**
* @name Music control functions.
* @{
*/
/**
* Fill PCM buffer.
*
* The sc68_process() function fills the PCM buffer with the current
* music data. If the current track is finished and it is not the last
* the next one is automatically loaded. The function returns status
* value that report events that have occured during this pass.
*
* @param sc68 sc68 instance.
* @param buf PCM buffer (must be at least 4*n bytes).
* @param n Pointer to number of PCM sample to fill.
*
* @return Process status
*
*/
int ;
/**
* Set/Get current track.
*
* The sc68_play() function get or set current track.
*
* If track == -1 and loop == 0 the function returns the current
* track or 0 if none.
*
* If track == -1 and loop != 0 the function returns the current
* loop counter.
*
* If track >= 0 the function will test the requested track
* number. If it is 0, the disk default track will be use. If the
* track is out of range, the function fails and returns -1 else it
* returns 0. To avoid multi-threading issus the track is not
* changed directly but a change-track event is posted. This event
* will be processed at the next call to the sc68_process()
* function. If loop is -1 the default music loop is used. If loop
* is 0 does an infinite loop.
*
* @param sc68 sc68 instance.
* @param track track number [-1:read current, 0:set disk default]
* @param loop number of loop [-1:default 0:infinite]
*
* @return error code or track number.
* @retval 0 Success or no current track
* @retval >0 Current track
* @retval -1 Failure.
*
*/
int ;
/**
* Stop playing.
*
* The sc68_stop() function stop current playing track. Like the
* sc68_play() function the sc68_stop() function does not really
* stop the music but send a stop-event that will be processed by
* the next call to sc68_process() function.
*
* @param sc68 sc68 instance.
* @return error code
* @retval 0 Success
* @retval -1 Failure
*/
int ;
/**
* Set/Get current play position.
*
* The sc68_seek() functions get or set the current play position.
*
* If time_ms == -1 the function returns the current play position
* or -1 if not currently playing.
*
* If time_ms >= 0 the function tries to seek to the given position.
* If time_ms is out of range the function returns -1.
* If time_ms is inside the current playing track the function does not
* seek backward.
* Else the function changes to the track which time_ms belong to and
* returns the time position at the beginning of this track.
*
* The returned time is always the current position in millisecond
* (not the goal position).
*
* @param sc68 sc68 instance.
* @param time_ms new time position in ms (-1:read current time).
* @param is_seeking Fill with current seek status (0:not seeking 1:seeking)
*
* @return Current play position (in ms)
* @retval >0 Success
* @retval -1 Failure
*
* @bug Time position calculation may be broken if tracks have different
* loop values. But it should not happen very often.
*/
int ;
/**
* Get disk/track information.
*
* @param info pointer to a sc68_music_info_t struct to be fill.
* @param sc68 sc68 instance
* @param track track number (-1 or 0:current/default).
* @param disk disk to get information from (0 for current disk).
*
* @return error code
* @retval 0 Success.
* @retval -1 Failure.
*
*/
int ;
/**
* @}
*/
/**
* @name File functions.
* @{
*/
/**
* Get official sc68 mime-type.
* @retval "audio/x-sc68"
*/
const char * ;
/**
* Create a stream from url. */
istream68_t * ;
/**
* Verify an sc68 disk. */
int ;
int ;
int ;
int ;
/**
* Load an sc68 disk for playing. */
int ;
int ;
int ;
/**
* Load an sc68 disk outside the API.
*
* @notice Free it with sc68_disk_free() function.
*/
sc68_disk_t ;
sc68_disk_t ;
sc68_disk_t ;
void ;
/**
* Change current disk.
*
* @param sc68 sc68 instance
* @param disk New disk (0 does a sc68_close())
*
* @return error code
* @retval 0 Success, disk has been loaded.
* @retval -1 Failure, no disk has been loaded (occurs if disk was 0).
*
* @note Can be safely call with null sc68.
* @warning After sc68_open() failure, the disk has been freed.
* @warning Beware not to use disk information after sc68_close() call
* because the disk should have been destroyed.
*/
int ;
/**
* Close current disk.
*
* @param sc68 sc68 instance
*
* @note Can be safely call with null sc68 or if no disk has been loaded.
*/
void ;
/**
* Get number of tracks.
*
* @param sc68 sc68 instance
*
* @return Number of track
* @retval -1 error
*
* @note Could be use to check if a disk is loaded.
*/
int ;
/**
* @}
*/
/**
* @name Configuration functions
* @{
*/
/**
* Load config.
*
* @param sc68 sc68 instance
*/
int ;
/**
* Save config.
*
* @param sc68 sc68 instance
*/
int ;
/**
* Apply current configuration to sc68.
*
* @param sc68 sc68 instance
*/
void ;
/**
* @}
*/
/**
* @name Dynamic memory access.
* @{
*/
/**
* Allocate dynamic memory.
*
* The sc68_alloc() function calls the alloc68() function.
*
* @param n Size of buffer to allocate.
*
* @return pointer to allocated memory buffer.
* @retval 0 error
*
* @see sc68_calloc()
* @see sc68_free()
*/
void * ;
/**
* Allocate zeroed dynamic memory.
*
* The sc68_calloc() function calls the calloc68() function.
*
* @param n Size of buffer to allocate.
*
* @return pointer to allocated memory buffer.
* @retval 0 error
*
* @see sc68_alloc()
* @see sc68_free()
*/
void * ;
/**
* Free dynamic memory.
*
* The sc68_free() function calls the free68() function.
*
* @param data Previously allocated memory buffer.
*
* @see sc68_alloc()
* @see sc68_calloc()
*/
void ;
/**
* @}
*/
/**
* @}
*/
/* #ifndef _SC68_SC68_H_ */