Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Setting the audio compressor through the API



ryan,

first create an atom container that holds your compression settings. you
will later pass this to the exporter..
i get the basis for my container from a soundDialog, then swap some atoms by
hand cause it wasn't doing it right for me.
also, i needed to be able to set this stuff without a dialog, which means
you have to build your atom container by hand more or less and pass it in.
Dean's Atomiser class is vital for debugging this sorta code.

here's a full method i wrote for setting export settings programatically.
if you can't get it to work i can just send you my whole class that handles
this audio export stuff off list,.



private AtomContainer _exportSettings;



/**
* Configure the sound exporter settings with or without a dialog
* @param numChannels 1 = mono, 2 = stereo
* @param sampleSize
* @param sampleRate
* @param compressionType a QuickTime constant specifying the compression
type
* @param showDialog whether to show the SoundCompressionDialog to allow
the user to choose
*/
public void setSoundExportSettings( int numChannels, int sampleSize, float
sampleRate, int compressionType, boolean showDialog ) {
try {
SoundCompressionDialog scd = new SoundCompressionDialog();
scd.setInfoSampleRate( sampleRate );
scd.setInfoSampleSize( sampleSize );
scd.setInfoCompression( compressionType );
scd.setInfoChannelCount( numChannels );
//Debug.trace( String.valueOf( "comp type : " +
scd.getInfoCompression() ) );

if ( showDialog )
scd.requestSettings();

// fill our atom container
_exportSettings = scd.getSettings();

if ( compressionType == StdQTConstants4.kQDesign2Compression ) {
// this requires a little explanation
// since the sound dialog component wasn't adding this atom 'cdec'
// for QDesign2, i'm just adding it myself here from the raw
// leaf data that i dumped out. it's a hack and hopefully
// i'll get whatever the legit version of this is before we
// call this production code, though this seems ok for now - rf

// the sound settings atom
Atom sounAtom = _exportSettings.findChildByIndex_Atom(
Atom.kParentIsContainer, QTUtils.toOSType("soun"), 1);

if ( sounAtom != null ) {
Atom cAtom = _exportSettings.findChildByIndex_Atom( sounAtom,
QTUtils.toOSType("cdec"), 1);

if ( cAtom == null ) {
// if it isn't there, lets add it...
int[] cdec = { 0x00, 0x00, 0x00, 0x0c, 0x66, 0x72, 0x6d, 0x61,
0x51, 0x44, 0x4d, 0x32, 0x00, 0x00, 0x00, 0x24,
0x51, 0x44, 0x43, 0x41, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x2b, 0x11,
0x00, 0x00, 0x5d, 0xc0, 0x00, 0x00, 0x04, 0x00,
0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x16,
0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 };

ByteArrayOutputStream bos = new ByteArrayOutputStream();

for (int i=0; i < cdec.length; i++)
bos.write( cdec[i] );

byte[] dataBytes = bos.toByteArray();
try {
bos.close();
} catch (Exception err) {}

Atom newCAtom = _exportSettings.insertChild(sounAtom,
QTUtils.toOSType("cdec"),
1,
1,
dataBytes);
if ( newCAtom == null )
Debug.trace("failed adding cdec atom");

}
}
}

//Debug.trace( String.valueOf( "comp type : " +
scd.getInfoCompression() ) );
//Debug.trace( "export settings : " + numChannels + ", " + sampleSize +
", " + sampleRate + ", " + compressionType);
//_dumper.dumpAtomContainer(new IndentPrintStream(), "_exportSettings ",
_exportSettings);

} catch ( QTException err ) {
Debug.trace( err.toString() );
}

}



then pass this to your movie exporter :



// the exporter will open a connection to the 'spit' component based
// on the export type we pass it
MovieExporter exp = new MovieExporter ( _exportType );


// settings have been configured
if ( _exportSettings != null ) {

// get the current settings of our exporter
AtomContainer settings = exp.getExportSettingsFromAtomContainer();
//_dumper.dumpAtomContainer(new IndentPrintStream(), "settings",
settings);

// first we locate the old 'soun' atom that holds our sound settings
Atom oldAtom = settings.findChildByIndex_Atom(
Atom.kParentIsContainer, QTUtils.toOSType("soun"), 1);
//Debug.trace("old 'soun' atom : " + oldAtom.toString());

// now we look in our _exportSettings container for the same atom
Atom newAtom = _exportSettings.findChildByIndex_Atom(
Atom.kParentIsContainer, QTUtils.toOSType("soun"), 1);
//Debug.trace("new 'soun' atom : " + newAtom.toString());

//delete the old sound settings atom
settings.removeAtom( oldAtom );

// pop in the new one from the preset settings
settings.insertChildren(Atom.kParentIsContainer, _exportSettings);

// dean's useful classes for debug :
//_dumper.dumpAtomContainer(new IndentPrintStream(), "_exportSettings
", _exportSettings);
//_dumper.dumpAtomContainer(new IndentPrintStream(), "NEW settings",
settings);

if ( settings != null )
exp.setExportSettingsFromAtomContainer( settings );

and so on...

good luck, rf
_______________________________________________
quicktime-java mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/quicktime-java
Do not post admin requests to the list. They will be ignored.

References: 
 >Setting the audio compressor through the API (From: Ryan Henderson <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.