API Reference¶
Complete API reference for coremusic. The package provides both functional and object-oriented APIs.
Note
The object-oriented API is recommended for new applications due to automatic resource management and Pythonic interfaces.
Object-Oriented API¶
High-level Pythonic wrappers with automatic resource management.
AudioFile Class¶
coremusic.audio.AudioFile
¶
Bases: CoreAudioObject
High-level audio file operations with automatic resource management
Source code in src/coremusic/audio/core.py
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 | |
_path = str(path)
instance-attribute
¶
_format = None
instance-attribute
¶
_is_open = False
instance-attribute
¶
_writable = writable
instance-attribute
¶
format
property
¶
Get the audio format of the file
metadata
property
¶
Read the info dictionary metadata from the audio file.
Returns a dict with string keys and string/number/bytes values, or None if the file format does not support metadata.
path
property
¶
Path the file was opened from
packet_count
property
¶
Number of audio packets in the file.
For uncompressed PCM one packet is one frame, so this is also the frame
count. It is the upper bound for :meth:read_packets.
duration
property
¶
Duration in seconds
__init__(path, *, writable=False)
¶
open()
¶
Open the audio file
Source code in src/coremusic/audio/core.py
close()
¶
Close the audio file
Source code in src/coremusic/audio/core.py
__enter__()
¶
__exit__(exc_type, exc_val, exc_tb)
¶
read_packets(start_packet, packet_count)
¶
Read audio packets from the file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_packet
|
int
|
Starting packet index (must be non-negative) |
required |
packet_count
|
int
|
Number of packets to read (must be positive) |
required |
Returns:
| Type | Description |
|---|---|
tuple[bytes, int]
|
Tuple of (audio_data_bytes, packets_read) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If start_packet < 0 or packet_count <= 0 |
AudioFileError
|
If reading fails |
Example::
from coremusic.audio import AudioFile
# Read audio data in chunks
with AudioFile("audio.wav") as audio:
chunk_size = 4096
offset = 0
while True:
data, packets_read = audio.read_packets(offset, chunk_size)
if packets_read == 0:
break
# Process data...
offset += packets_read
Source code in src/coremusic/audio/core.py
read_as_numpy(start_packet=0, packet_count=None)
¶
Read audio data from the file as a NumPy array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_packet
|
int
|
Starting packet index (default: 0) |
0
|
packet_count
|
int | None
|
Number of packets to read (default: all remaining packets) |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[Any]
|
NumPy array with shape (frames, channels) for multi-channel audio, |
NDArray[Any]
|
or (frames,) for mono audio. The dtype is determined by the audio format. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If NumPy is not available |
AudioFileError
|
If reading fails |
Example:
with AudioFile("audio.wav") as audio:
data = audio.read_as_numpy()
print(f"Shape: {data.shape}, dtype: {data.dtype}")
# output: Shape: (44100, 2), dtype: int16
Source code in src/coremusic/audio/core.py
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 | |
get_property(property_id)
¶
Get a property from the audio file
Source code in src/coremusic/audio/core.py
set_property(property_id, data)
¶
Set a property on the audio file.
The file must have been opened with writable=True.
Source code in src/coremusic/audio/core.py
set_metadata(tags)
¶
Write metadata tags to the audio file.
The file must have been opened with writable=True. Keys should be strings. Values can be str, int, or float.
Common keys: 'title', 'artist', 'album', 'genre', 'year', 'track number', 'comments', 'approximate duration in seconds'.
Source code in src/coremusic/audio/core.py
__repr__()
¶
dispose()
¶
Dispose of the audio file
Source code in src/coremusic/audio/core.py
AudioFormat Class¶
coremusic.audio.AudioFormat
¶
Pythonic representation of AudioStreamBasicDescription
Source code in src/coremusic/audio/core.py
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 | |
sample_rate = sample_rate
instance-attribute
¶
format_id = format_id
instance-attribute
¶
format_flags = format_flags
instance-attribute
¶
bytes_per_packet = bytes_per_packet
instance-attribute
¶
frames_per_packet = frames_per_packet
instance-attribute
¶
bytes_per_frame = bytes_per_frame
instance-attribute
¶
channels_per_frame = channels_per_frame
instance-attribute
¶
bits_per_channel = bits_per_channel
instance-attribute
¶
is_pcm
property
¶
Check if this is a PCM format
is_compressed
property
¶
Check if this is a compressed (non-PCM) format coremusic can encode.
is_stereo
property
¶
Check if this is stereo (2 channels)
is_mono
property
¶
Check if this is mono (1 channel)
__init__(sample_rate, format_id, format_flags=0, bytes_per_packet=0, frames_per_packet=0, bytes_per_frame=0, channels_per_frame=2, bits_per_channel=16)
¶
Source code in src/coremusic/audio/core.py
from_asbd_bytes(data)
classmethod
¶
Parse an AudioStreamBasicDescription (40 bytes) into an AudioFormat.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
Raw ASBD bytes (at least 40 bytes) |
required |
Returns:
| Type | Description |
|---|---|
AudioFormat
|
AudioFormat with parsed fields |
Raises:
| Type | Description |
|---|---|
ValueError
|
If data is too short |
Source code in src/coremusic/audio/core.py
pcm(sample_rate=44100.0, channels=2, bits=16, is_float=False, big_endian=False)
classmethod
¶
Create a packed PCM AudioFormat with correctly computed derived fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_rate
|
float
|
Sample rate in Hz (default: 44100.0) |
44100.0
|
channels
|
int
|
Number of channels (default: 2) |
2
|
bits
|
int
|
Bits per sample (default: 16) |
16
|
is_float
|
bool
|
If True, create float format; otherwise signed integer |
False
|
big_endian
|
bool
|
If True, mark the samples as big-endian. macOS is little-endian natively, so set this only for containers that require it, such as AIFF. |
False
|
Returns:
| Type | Description |
|---|---|
AudioFormat
|
AudioFormat with all ASBD fields correctly computed |
Source code in src/coremusic/audio/core.py
aac(sample_rate=44100.0, channels=2)
classmethod
¶
Create an AAC (lossy) compressed format description.
The returned description is suitable as the file format when creating an ExtAudioFile for encoding; the PCM feed is supplied separately as the client format. CoreAudio fills in the encoder-specific fields, so the packet/frame/bit fields are left at their canonical AAC values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_rate
|
float
|
Sample rate in Hz (default: 44100.0) |
44100.0
|
channels
|
int
|
Number of channels (default: 2) |
2
|
Source code in src/coremusic/audio/core.py
alac(sample_rate=44100.0, channels=2)
classmethod
¶
Create an Apple Lossless (ALAC) compressed format description.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_rate
|
float
|
Sample rate in Hz (default: 44100.0) |
44100.0
|
channels
|
int
|
Number of channels (default: 2) |
2
|
Source code in src/coremusic/audio/core.py
flac(sample_rate=44100.0, channels=2)
classmethod
¶
Create a FLAC (lossless) compressed format description.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_rate
|
float
|
Sample rate in Hz (default: 44100.0) |
44100.0
|
channels
|
int
|
Number of channels (default: 2) |
2
|
Source code in src/coremusic/audio/core.py
to_dict()
¶
Convert to dictionary format for functional API
Source code in src/coremusic/audio/core.py
to_numpy_dtype()
¶
Convert audio format to NumPy dtype for audio data arrays.
Returns:
| Type | Description |
|---|---|
dtype[Any]
|
NumPy dtype object suitable for audio data representation |
Raises:
| Type | Description |
|---|---|
ImportError
|
If NumPy is not available |
ValueError
|
If format cannot be converted to NumPy dtype |
Source code in src/coremusic/audio/core.py
AudioUnit Class¶
coremusic.audio.AudioUnit
¶
Bases: CoreAudioObject
Audio unit for real-time audio processing
Source code in src/coremusic/audio/units.py
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 | |
_description = description
instance-attribute
¶
_is_initialized = False
instance-attribute
¶
sample_rate
property
writable
¶
Get the sample rate (kAudioUnitProperty_SampleRate on global scope)
latency
property
¶
Get the latency in seconds (kAudioUnitProperty_Latency)
cpu_load
property
¶
Get the CPU load as a fraction (0.0 to 1.0) (kAudioUnitProperty_CPULoad)
max_frames_per_slice
property
writable
¶
Get the maximum frames per slice (kAudioUnitProperty_MaximumFramesPerSlice)
is_initialized
property
¶
__init__(description)
¶
default_output()
classmethod
¶
Create a default output AudioUnit
Source code in src/coremusic/audio/units.py
initialize()
¶
Initialize the AudioUnit
Source code in src/coremusic/audio/units.py
uninitialize()
¶
Uninitialize the AudioUnit
Source code in src/coremusic/audio/units.py
start()
¶
Start the AudioUnit output
Source code in src/coremusic/audio/units.py
stop()
¶
Stop the AudioUnit output
get_property(property_id, scope, element)
¶
Get a property from the AudioUnit
Source code in src/coremusic/audio/units.py
set_property(property_id, scope, element, data)
¶
Set a property on the AudioUnit
Source code in src/coremusic/audio/units.py
get_stream_format(scope='output', element=0)
¶
Get the stream format for a specific scope and element
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
str
|
'input', 'output', or 'global' (default: 'output') |
'output'
|
element
|
int
|
Element index (default: 0) |
0
|
Returns:
| Type | Description |
|---|---|
AudioFormat
|
AudioFormat object with the current stream format |
Raises:
| Type | Description |
|---|---|
AudioUnitError
|
If scope is invalid or getting format fails |
Example::
# Get the output format of an AudioUnit
with AudioUnit(component) as unit:
format = unit.get_stream_format('output', 0)
print(f"Sample rate: {format.sample_rate}")
print(f"Channels: {format.channels_per_frame}")
print(f"Bits: {format.bits_per_channel}")
Source code in src/coremusic/audio/units.py
set_stream_format(format, scope='output', element=0)
¶
Set the stream format for a specific scope and element
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
format
|
AudioFormat
|
AudioFormat object with desired format |
required |
scope
|
str
|
'input', 'output', or 'global' (default: 'output') |
'output'
|
element
|
int
|
Element index (must be non-negative, default: 0) |
0
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If format is not an AudioFormat |
ValueError
|
If scope is invalid or element is negative |
AudioUnitError
|
If setting format fails |
Example::
from coremusic.audio import AudioFormat, AudioUnit
# Create a stereo 44.1kHz 16-bit PCM format
format = AudioFormat(
sample_rate=44100.0,
format_id='lpcm',
channels_per_frame=2,
bits_per_channel=16
)
# Set the input format on an effect unit
with AudioUnit(effect_component) as effect:
effect.set_stream_format(format, 'input', 0)
Source code in src/coremusic/audio/units.py
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 | |
get_parameter_list(scope='global')
¶
Get list of available parameter IDs (kAudioUnitProperty_ParameterList)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
str
|
'input', 'output', or 'global' (default: 'global') |
'global'
|
Returns:
| Type | Description |
|---|---|
list[int]
|
List of parameter IDs |
Source code in src/coremusic/audio/units.py
render(input_data, num_frames, sample_rate=44100.0, channels=2)
¶
Render audio through this unit for offline (effect) processing.
Feeds input_data to the unit via an input render callback and reads
its output, handling the canonical non-interleaved float32 layout that
most effect AudioUnits use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
|
bytes
|
Input audio as interleaved float32 bytes |
required |
num_frames
|
int
|
Number of frames to render |
required |
sample_rate
|
float
|
Sample rate in Hz (default: 44100.0) |
44100.0
|
channels
|
int
|
Channel count (default: 2) |
2
|
Returns:
| Type | Description |
|---|---|
bytes
|
Processed audio as interleaved float32 bytes. |
Note
This drives an effect unit. Instrument (music device) units should
be rendered with coremusic.audio.audiounit_host.render_midi_file
or AudioUnitPlugin.render_midi instead.
Source code in src/coremusic/audio/units.py
__repr__()
¶
Source code in src/coremusic/audio/units.py
__enter__()
¶
__exit__(exc_type, exc_val, exc_tb)
¶
dispose()
¶
Dispose of the AudioUnit
Source code in src/coremusic/audio/units.py
AudioQueue Class¶
coremusic.audio.AudioQueue
¶
Bases: CoreAudioObject
Audio queue for buffered playback and recording
Source code in src/coremusic/audio/core.py
1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 | |
_format = audio_format
instance-attribute
¶
_buffers = []
instance-attribute
¶
__init__(audio_format)
¶
new_output(audio_format)
classmethod
¶
Create a new output audio queue
Source code in src/coremusic/audio/core.py
allocate_buffer(buffer_size)
¶
Allocate an audio buffer
Source code in src/coremusic/audio/core.py
enqueue_buffer(buffer)
¶
Enqueue an audio buffer
Source code in src/coremusic/audio/core.py
start()
¶
Start the audio queue
stop(immediate=True)
¶
Stop the audio queue
Source code in src/coremusic/audio/core.py
__repr__()
¶
dispose(immediate=True)
¶
Dispose of the audio queue
Source code in src/coremusic/audio/core.py
AudioConverter Class¶
coremusic.audio.AudioConverter
¶
Bases: CoreAudioObject
Audio format converter for sample rate and format conversion
Provides high-level interface for converting between audio formats, sample rates, bit depths, and channel configurations.
Source code in src/coremusic/audio/core.py
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 | |
_source_format = source_format
instance-attribute
¶
_dest_format = dest_format
instance-attribute
¶
source_format
property
¶
Get source audio format
dest_format
property
¶
Get destination audio format
__init__(source_format, dest_format)
¶
Create an AudioConverter
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_format
|
AudioFormat
|
Source audio format |
required |
dest_format
|
AudioFormat
|
Destination audio format |
required |
Raises:
| Type | Description |
|---|---|
AudioConverterError
|
If converter creation fails |
Source code in src/coremusic/audio/core.py
convert(audio_data)
¶
Convert audio data from source to destination format
This method uses the simple buffer-based API (AudioConverterConvertBuffer) which only supports conversions where the input/output sizes are predictable. For complex conversions (sample rate, bit depth), use convert_with_callback().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
audio_data
|
bytes
|
Input audio data in source format (raw PCM samples) |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
Converted audio data in destination format |
Raises:
| Type | Description |
|---|---|
AudioConverterError
|
If conversion fails |
Example:
# Convert stereo to mono (simple format conversion)
source = AudioFormat(44100.0, 'lpcm', channels_per_frame=2, bits_per_channel=16)
dest = AudioFormat(44100.0, 'lpcm', channels_per_frame=1, bits_per_channel=16)
with AudioConverter(source, dest) as converter:
stereo_data = b'\x00\x00\xff\xff' * 1024 # Raw 16-bit stereo samples
mono_data = converter.convert(stereo_data)
Source code in src/coremusic/audio/core.py
convert_with_callback(input_data, input_packet_count, output_packet_count=None)
¶
Convert audio using callback-based API for complex conversions
This method supports all types of conversions including: - Sample rate changes (e.g., 44.1kHz -> 48kHz) - Bit depth changes (e.g., 16-bit -> 24-bit) - Channel count changes (stereo <-> mono) - Combinations of the above
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
|
bytes
|
Input audio data as bytes |
required |
input_packet_count
|
int
|
Number of packets in input data |
required |
output_packet_count
|
int | None
|
Expected output packets (auto-calculated if None) |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
Converted audio data as bytes |
Raises:
| Type | Description |
|---|---|
AudioConverterError
|
If conversion fails |
Example:
# Convert 44.1kHz to 48kHz
source_format = AudioFormat(44100.0, 'lpcm', channels_per_frame=2, bits_per_channel=16)
dest_format = AudioFormat(48000.0, 'lpcm', channels_per_frame=2, bits_per_channel=16)
with AudioConverter(source_format, dest_format) as converter:
# Read input data
with AudioFile("input_44100.wav") as af:
input_data, packet_count = af.read_packets(0, 999999999)
# Convert
output_data = converter.convert_with_callback(input_data, packet_count)
# Write output
with ExtendedAudioFile.create("output_48000.wav", 'WAVE', dest_format) as out:
num_frames = len(output_data) // dest_format.bytes_per_frame
out.write(num_frames, output_data)
Source code in src/coremusic/audio/core.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 | |
get_property(property_id)
¶
Get a property from the converter
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property_id
|
int
|
Property ID |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
Property data as bytes |
Raises:
| Type | Description |
|---|---|
AudioConverterError
|
If getting property fails |
Source code in src/coremusic/audio/core.py
set_property(property_id, data)
¶
Set a property on the converter
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property_id
|
int
|
Property ID (from capi.get_audio_converter_property_*()) |
required |
data
|
bytes
|
Property data as bytes (use struct.pack for binary encoding) |
required |
Raises:
| Type | Description |
|---|---|
AudioConverterError
|
If setting property fails |
Example:
import struct
import coremusic as cm
converter = AudioConverter(source_fmt, dest_fmt)
# Set bitrate to 128 kbps (requires UInt32)
bitrate_prop = cm.capi.get_audio_converter_property_bit_rate()
converter.set_property(bitrate_prop, struct.pack('<I', 128000))
# Set quality (requires UInt32, 0=lowest, 127=highest)
quality_prop = cm.capi.get_audio_converter_property_quality()
converter.set_property(quality_prop, struct.pack('<I', 127))
Source code in src/coremusic/audio/core.py
reset()
¶
Reset the converter to its initial state
Source code in src/coremusic/audio/core.py
dispose()
¶
Dispose of the audio converter
__enter__()
¶
__exit__(exc_type, exc_val, exc_tb)
¶
MIDIClient Class¶
coremusic.midi.MIDIClient
¶
Bases: CoreAudioObject
MIDI client for managing MIDI operations
Source code in src/coremusic/midi/core.py
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 | |
_name = name
instance-attribute
¶
_ports = []
instance-attribute
¶
_endpoints = []
instance-attribute
¶
name
property
¶
__init__(name)
¶
Source code in src/coremusic/midi/core.py
__repr__()
¶
__enter__()
¶
__exit__(exc_type, exc_val, exc_tb)
¶
create_input_port(name, callback=None, queue_size=4096)
¶
Create a MIDI input port.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name for the port |
required |
callback
|
Callable[[bytes, int], None] | None
|
Optional |
None
|
queue_size
|
int
|
Maximum buffered packets when no callback is given |
4096
|
Source code in src/coremusic/midi/core.py
create_output_port(name)
¶
Create a MIDI output port
Source code in src/coremusic/midi/core.py
create_virtual_source(name)
¶
Create a virtual MIDI source owned by this client.
The source appears to other applications as a MIDI input they can
connect to. Produce MIDI from it with :meth:MIDIEndpoint.send.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name published to CoreMIDI |
required |
Returns:
| Type | Description |
|---|---|
MIDIEndpoint
|
The virtual source endpoint, disposed with this client |
Source code in src/coremusic/midi/core.py
create_virtual_destination(name, callback=None, queue_size=4096)
¶
Create a virtual MIDI destination owned by this client.
The destination appears to other applications as a MIDI output they can send to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name published to CoreMIDI |
required |
callback
|
Callable[[bytes, int], None] | None
|
Optional |
None
|
queue_size
|
int
|
Maximum buffered packets when no callback is given |
4096
|
Returns:
| Type | Description |
|---|---|
MIDIEndpoint
|
The virtual destination endpoint, disposed with this client |
Source code in src/coremusic/midi/core.py
dispose()
¶
Dispose of the MIDI client, its ports and its virtual endpoints
Source code in src/coremusic/midi/core.py
MIDIInputPort Class¶
coremusic.midi.MIDIInputPort
¶
Bases: MIDIPort
MIDI input port for receiving MIDI data.
Unless the port was created with a callback, incoming packets are buffered
and retrieved with :meth:poll::
client = MIDIClient("MyApp")
port = client.create_input_port("Input")
port.connect_source(source)
while True:
if port.wait(0.1):
for host_time, payload in port.poll():
print(host_time, payload.hex())
Source code in src/coremusic/midi/core.py
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 | |
pending
property
¶
Number of packets currently buffered.
dropped
property
¶
Number of packets discarded because the buffer was full.
A non-zero value means this port is not being polled fast enough, or
that it was created with too small a queue_size.
connect_source(source)
¶
Connect to a MIDI source
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
MIDIEndpoint | int
|
A :class: |
required |
Source code in src/coremusic/midi/core.py
disconnect_source(source)
¶
Disconnect from a MIDI source
Source code in src/coremusic/midi/core.py
poll(max_events=0)
¶
Drain the buffered incoming packets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_events
|
int
|
Maximum number of packets to return, or 0 for all |
0
|
Returns:
| Type | Description |
|---|---|
list[tuple[int, bytes]]
|
List of (host_time, data) tuples in arrival order. Convert |
list[tuple[int, bytes]]
|
host_time to seconds with |
list[tuple[int, bytes]]
|
packet may hold more than one MIDI message; use |
list[tuple[int, bytes]]
|
class: |
list[tuple[int, bytes]]
|
port created with a callback. |
Source code in src/coremusic/midi/core.py
wait(timeout=None)
¶
Block until at least one packet is buffered or the timeout expires.
Returns:
| Type | Description |
|---|---|
bool
|
True if packets are available, False if the timeout expired |
Source code in src/coremusic/midi/core.py
MIDIOutputPort Class¶
coremusic.midi.MIDIOutputPort
¶
Bases: MIDIPort
MIDI output port for sending MIDI data
Source code in src/coremusic/midi/core.py
send_data(destination, data, timestamp=0)
¶
Send MIDI data to a destination endpoint
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
destination
|
MIDIEndpoint | int
|
A :class: |
required |
data
|
bytes
|
MIDI message bytes (following MIDI protocol specification) |
required |
timestamp
|
int
|
MIDI timestamp (0 for immediate, or future timestamp) |
0
|
Raises:
| Type | Description |
|---|---|
MIDIError
|
If sending fails |
Example::
from coremusic.constants import MIDIControlChange
from coremusic.midi import (
MIDIClient,
control_change,
get_destinations,
note_off,
note_on,
)
client = MIDIClient("MyApp")
output_port = client.create_output_port("Output")
# Pick a destination: a hardware or software endpoint published by
# the system, or a virtual one owned by this process.
destinations = get_destinations()
if destinations:
destination = destinations[0]
else:
destination = client.create_virtual_destination("Synth")
# Send Note On (middle C, velocity 100)
output_port.send_data(destination, note_on("C4", 100))
# Send Control Change (volume to 127)
output_port.send_data(
destination, control_change(MIDIControlChange.VOLUME, 127)
)
# Send Note Off
output_port.send_data(destination, note_off("C4"))
client.dispose()
Source code in src/coremusic/midi/core.py
MIDIEndpoint Class¶
coremusic.midi.MIDIEndpoint
¶
Bases: CoreAudioObject
A MIDI endpoint: either a source (produces MIDI) or a destination (consumes MIDI).
Endpoints come from two places:
- The system, via :func:
get_sources/ :func:get_destinations. These belong to other applications or hardware and are never disposed here. - This process, via :meth:
MIDIClient.create_virtual_sourceand :meth:MIDIClient.create_virtual_destination. These are owned, and :meth:disposedestroys them.
A virtual destination created without a callback buffers incoming packets;
retrieve them with :meth:poll, as for :class:MIDIInputPort.
Source code in src/coremusic/midi/core.py
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 | |
_owned = owned
instance-attribute
¶
_client = None
instance-attribute
¶
_name = name or ''
instance-attribute
¶
name
property
¶
Name of the endpoint as published to CoreMIDI
is_owned
property
¶
True for virtual endpoints created by this process
pending
property
¶
Number of packets currently buffered.
dropped
property
¶
Number of packets discarded because the buffer was full.
__init__(endpoint_id, name=None, owned=False)
¶
Source code in src/coremusic/midi/core.py
__repr__()
¶
__enter__()
¶
__exit__(exc_type, exc_val, exc_tb)
¶
send(data, timestamp=0)
¶
Distribute MIDI data from this virtual source to its connections.
This is the counterpart of :meth:MIDIOutputPort.send_data: it makes
the endpoint behave as if a device had just produced the given bytes.
Only meaningful for an endpoint from
:meth:MIDIClient.create_virtual_source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
MIDI message bytes |
required |
timestamp
|
int
|
MIDI timestamp (0 for immediate) |
0
|
Raises:
| Type | Description |
|---|---|
MIDIError
|
If distribution fails |
Source code in src/coremusic/midi/core.py
poll(max_events=0)
¶
Drain packets buffered by this virtual destination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_events
|
int
|
Maximum number of packets to return, or 0 for all |
0
|
Returns:
| Type | Description |
|---|---|
list[tuple[int, bytes]]
|
List of (host_time, data) tuples in arrival order. Always empty for |
list[tuple[int, bytes]]
|
a destination created with a callback. |
Source code in src/coremusic/midi/core.py
wait(timeout=None)
¶
Block until at least one packet is buffered or the timeout expires.
Returns:
| Type | Description |
|---|---|
bool
|
True if packets are available, False if the timeout expired |
Source code in src/coremusic/midi/core.py
dispose()
¶
Dispose of a virtual endpoint.
A system endpoint is owned by another process, so this only marks the wrapper as disposed and leaves the endpoint alone.
Source code in src/coremusic/midi/core.py
Endpoint Discovery¶
coremusic.midi.get_sources()
¶
List the MIDI sources currently published by the system.
Returns:
| Name | Type | Description |
|---|---|---|
list[MIDIEndpoint]
|
Source endpoints, in CoreMIDI index order. These are inputs to this |
|
process |
list[MIDIEndpoint]
|
connect one to a :class: |
Source code in src/coremusic/midi/core.py
coremusic.midi.get_destinations()
¶
List the MIDI destinations currently published by the system.
Returns:
| Type | Description |
|---|---|
list[MIDIEndpoint]
|
Destination endpoints, in CoreMIDI index order. These are outputs from |
list[MIDIEndpoint]
|
this process: pass one to :meth: |
Source code in src/coremusic/midi/core.py
coremusic.midi.find_source(name)
¶
Find a MIDI source by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Exact name, or a substring matched case-insensitively when no exact match exists |
required |
Returns:
| Type | Description |
|---|---|
MIDIEndpoint | None
|
The first matching source, or None |
Source code in src/coremusic/midi/core.py
coremusic.midi.find_destination(name)
¶
Find a MIDI destination by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Exact name, or a substring matched case-insensitively when no exact match exists |
required |
Returns:
| Type | Description |
|---|---|
MIDIEndpoint | None
|
The first matching destination, or None |
Source code in src/coremusic/midi/core.py
AudioClock Class¶
coremusic.audio.AudioClock
¶
Bases: CoreAudioObject
High-level CoreAudioClock for audio/MIDI synchronization and timing
AudioClock provides synchronization services for audio and MIDI applications, supporting multiple time formats and playback control.
Supported time formats:
- Host time (mach_absolute_time)
- Audio samples
- Musical beats
- Seconds
- SMPTE timecode
Example::
# Create and control a clock
with AudioClock() as clock:
clock.play_rate = 1.0
clock.start()
# Get current time in different formats
seconds = clock.get_time_seconds()
beats = clock.get_time_beats()
print(f"Position: {seconds:.2f}s ({beats:.2f} beats)")
clock.stop()
Example with tempo and speed control::
clock = AudioClock()
clock.play_rate = 0.5 # Half speed
clock.start()
# ... use clock for synchronization
clock.stop()
clock.dispose()
Source code in src/coremusic/audio/clock.py
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 | |
_is_created = False
instance-attribute
¶
_is_running = False
instance-attribute
¶
is_running
property
¶
Check if the clock is currently running
play_rate
property
writable
¶
Get or set the playback rate (1.0 = normal speed)
__init__()
¶
create()
¶
Create the underlying clock object
Returns:
| Type | Description |
|---|---|
AudioClock
|
Self for method chaining |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If clock creation fails |
Source code in src/coremusic/audio/clock.py
start()
¶
Start the clock advancing on its timeline
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If clock is not created or start fails |
Source code in src/coremusic/audio/clock.py
stop()
¶
Stop the clock
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If stop fails |
Source code in src/coremusic/audio/clock.py
get_current_time(time_format)
¶
Get current time in specified format
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_format
|
int
|
Time format constant from ClockTimeFormat |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with 'format' and 'value' keys |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If getting time fails |
Source code in src/coremusic/audio/clock.py
get_time_seconds()
¶
Get current time in seconds
Returns:
| Type | Description |
|---|---|
float
|
Current time in seconds |
get_time_beats()
¶
Get current time in musical beats
Returns:
| Type | Description |
|---|---|
float
|
Current time in beats |
get_time_samples()
¶
Get current time in audio samples
Returns:
| Type | Description |
|---|---|
float
|
Current time in samples |
get_time_host()
¶
Get current time as host time
Returns:
| Type | Description |
|---|---|
int
|
Current host time (mach_absolute_time) |
get_smpte_time()
¶
Get current time as SMPTE timecode
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
Dictionary with SMPTE time components: |
dict[str, int]
|
|
dict[str, int]
|
|
dict[str, int]
|
|
Source code in src/coremusic/audio/clock.py
dispose()
¶
Dispose the clock and free resources
Source code in src/coremusic/audio/clock.py
__enter__()
¶
__exit__(exc_type, exc_val, exc_tb)
¶
__repr__()
¶
Source code in src/coremusic/audio/clock.py
ClockTimeFormat¶
coremusic.audio.ClockTimeFormat
¶
Time format constants for CoreAudioClock
Source code in src/coremusic/audio/clock.py
HOST_TIME = capi.get_ca_clock_time_format_host_time()
class-attribute
instance-attribute
¶
SAMPLES = capi.get_ca_clock_time_format_samples()
class-attribute
instance-attribute
¶
BEATS = capi.get_ca_clock_time_format_beats()
class-attribute
instance-attribute
¶
SECONDS = capi.get_ca_clock_time_format_seconds()
class-attribute
instance-attribute
¶
SMPTE_TIME = capi.get_ca_clock_time_format_smpte_time()
class-attribute
instance-attribute
¶
AudioEffectsChain Class¶
coremusic.audio.AudioEffectsChain
¶
High-level audio effects chain using AUGraph.
Provides a simplified API for creating and managing chains of AudioUnit effects for real-time audio processing.
Example
from coremusic.audio.utilities import AudioEffectsChain
# Create an effects chain
chain = AudioEffectsChain()
# Add effects (example effect types)
reverb_node = chain.add_effect('aumu', 'rvb2', 'appl') # Reverb
eq_node = chain.add_effect('aufx', 'eqal', 'appl') # EQ
# Connect to output
output_node = chain.add_output()
chain.connect(reverb_node, eq_node)
chain.connect(eq_node, output_node)
# Initialize and start
chain.initialize()
chain.start()
# ... process audio ...
# Cleanup
chain.stop()
chain.dispose()
Source code in src/coremusic/audio/utilities.py
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 | |
_graph = AUGraph()
instance-attribute
¶
_nodes = {}
instance-attribute
¶
graph
property
¶
Get the underlying AUGraph
is_open
property
¶
Check if the graph is open
is_initialized
property
¶
Check if the graph is initialized
is_running
property
¶
Check if the graph is running
node_count
property
¶
Get the number of nodes in the chain
__init__()
¶
add_effect(effect_type, effect_subtype, manufacturer='appl', flags=0)
¶
Add an audio effect to the chain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
effect_type
|
str
|
AudioUnit type (4-char code or string) |
required |
effect_subtype
|
str
|
AudioUnit subtype (4-char code or string) |
required |
manufacturer
|
str
|
Manufacturer code (default: 'appl' for Apple) |
'appl'
|
flags
|
int
|
Component flags (default: 0) |
0
|
Returns:
| Type | Description |
|---|---|
int
|
Node ID for this effect |
Example
Source code in src/coremusic/audio/utilities.py
add_effect_by_name(name)
¶
Add an audio effect to the chain by name.
This searches for an AudioUnit matching the given name and adds it to the chain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
AudioUnit name (e.g., 'AUDelay', 'Reverb', 'AUGraphicEQ') |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
Node ID for this effect, or None if not found |
Example
Source code in src/coremusic/audio/utilities.py
add_output(output_type='auou', output_subtype='def ')
¶
Add an output node to the chain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_type
|
str
|
Output type (default: 'auou' for AudioUnit Output) |
'auou'
|
output_subtype
|
str
|
Output subtype (default: 'def ' for default output) |
'def '
|
Returns:
| Type | Description |
|---|---|
int
|
Node ID for the output |
Example
Source code in src/coremusic/audio/utilities.py
connect(source_node, dest_node, source_bus=0, dest_bus=0)
¶
Connect two nodes in the effects chain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_node
|
int
|
Source node ID |
required |
dest_node
|
int
|
Destination node ID |
required |
source_bus
|
int
|
Source output bus (default: 0) |
0
|
dest_bus
|
int
|
Destination input bus (default: 0) |
0
|
Example
Source code in src/coremusic/audio/utilities.py
disconnect(dest_node, dest_bus=0)
¶
Disconnect a node input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dest_node
|
int
|
Destination node ID |
required |
dest_bus
|
int
|
Destination input bus (default: 0) |
0
|
Source code in src/coremusic/audio/utilities.py
remove_node(node_id)
¶
Remove a node from the chain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
int
|
Node ID to remove |
required |
open()
¶
Open the graph (opens all AudioUnits).
Returns:
| Type | Description |
|---|---|
AudioEffectsChain
|
Self for method chaining |
initialize()
¶
Initialize the graph (prepares for rendering).
Returns:
| Type | Description |
|---|---|
AudioEffectsChain
|
Self for method chaining |
start()
¶
stop()
¶
dispose()
¶
__enter__()
¶
Functional API¶
Low-level C-style functions are available through the coremusic.capi module
for advanced use cases requiring direct access to CoreAudio frameworks.
Note
The object-oriented API is recommended for most use cases. The functional
API in coremusic.capi provides low-level access when needed.
For direct access to low-level functions:
from coremusic import capi
# Low-level audio file operations
file_id = capi.audio_file_open_url("audio.wav")
# ... operations ...
capi.audio_file_close(file_id)
# Low-level clock operations
clock_id = capi.ca_clock_new()
capi.ca_clock_start(clock_id)
# ... operations ...
capi.ca_clock_dispose(clock_id)
Error Handling¶
coremusic provides exception classes for different CoreAudio subsystems:
coremusic.exceptions.CoreAudioError
¶
Bases: Exception
Base exception for CoreAudio errors
Source code in src/coremusic/exceptions.py
status_code = status_code
instance-attribute
¶
__init__(message, status_code=0)
¶
from_os_status(status, operation='')
classmethod
¶
Create exception from OSStatus code with human-readable error message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
int
|
OSStatus error code |
required |
operation
|
str
|
Description of failed operation (e.g., "open audio file") |
''
|
Returns:
| Type | Description |
|---|---|
CoreAudioError
|
CoreAudioError with formatted message including error name and suggestion |
Source code in src/coremusic/exceptions.py
coremusic.exceptions.AudioFileError
¶
coremusic.exceptions.AudioUnitError
¶
coremusic.exceptions.AudioQueueError
¶
Bases: CoreAudioError
Exception for AudioQueue operations
Source code in src/coremusic/exceptions.py
coremusic.exceptions.AudioConverterError
¶
Bases: CoreAudioError
Exception for AudioConverter operations
Source code in src/coremusic/exceptions.py
coremusic.exceptions.MIDIError
¶
coremusic.exceptions.MusicPlayerError
¶
Bases: CoreAudioError
Exception for MusicPlayer operations
Source code in src/coremusic/exceptions.py
coremusic.exceptions.AudioDeviceError
¶
Bases: CoreAudioError
Exception for AudioDevice operations
Source code in src/coremusic/exceptions.py
coremusic.exceptions.AUGraphError
¶
Utility Functions¶
Utility functions are available through coremusic.capi for FourCC conversion
and other low-level operations: