假设我使用的是具有泛型类型参数的接口
interface Foo<T> {
T getOne();
void useOne(T t);
}
Run Code Online (Sandbox Code Playgroud)
意图是类型T是抽象的:它对实现强制执行类型约束Foo,但客户端代码并不关心究竟是什么T.
这在通用方法的上下文中没有问题:
public <T> void doStuff(Foo<T> foo) {
T t = foo.getOne();
/* do stuff */
foo.useOne(t);
}
Run Code Online (Sandbox Code Playgroud)
但是假设我想要分解工作doStuff,在课堂上保存一些状态Bar.在这种情况下,我似乎需要添加的类型参数Foo来Bar.
public class Bar<T> {
private Foo<T> foo;
private T t;
/* ... */
public void startStuff() {
t = foo.getOne();
}
public void finishStuff() {
foo.useOne(t);
}
}
Run Code Online (Sandbox Code Playgroud)
这有点奇怪,因为类型参数T没有出现在公共接口中Bar(即,它不包含在任何方法参数或返回类型中).有没有办法"量化T"?即,我可以安排将参数T隐藏在界面中 …
在Java中,是否有可能强制某个类具有一组特定的子类而没有其他子类?例如:
public abstract class A {}
public final class B extends A {}
public final class C extends A {}
public final class D extends A {}
Run Code Online (Sandbox Code Playgroud)
我可以以某种方式强制执行不能创建A的其他子类吗?
我想在我的应用程序中实现SIP调用,我需要解决的第一个问题是将带有ADTS标头的压缩AAC格式的音频转换为线性PCM.
我的输入数据是具有不同帧大小的ADTS帧的NSArray.每个帧都是NSMutableData类型.每个帧具有相同的格式和采样率,唯一的区别是帧大小.
我尝试实现Igor Rotaru 为此问题建议的示例代码,但无法使其工作.
现在我的代码看起来像这样.首先,我配置AudioConverter:
- (void)configureAudioConverter {
AudioStreamBasicDescription inFormat;
memset(&inFormat, 0, sizeof(inFormat));
inputFormat.mBitsPerChannel = 0;
inputFormat.mBytesPerFrame = 0;
inputFormat.mBytesPerPacket = 0;
inputFormat.mChannelsPerFrame = 1;
inputFormat.mFormatFlags = kMPEG4Object_AAC_LC;
inputFormat.mFormatID = kAudioFormatMPEG4AAC;
inputFormat.mFramesPerPacket = 1024;
inputFormat.mReserved = 0;
inputFormat.mSampleRate = 22050;
AudioStreamBasicDescription outputFormat;
memset(&outputFormat, 0, sizeof(outputFormat));
outputFormat.mSampleRate = inputFormat.mSampleRate;
outputFormat.mFormatID = kAudioFormatLinearPCM;
outputFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger;
outputFormat.mBytesPerPacket = 2;
outputFormat.mFramesPerPacket = 1;
outputFormat.mBytesPerFrame = 2;
outputFormat.mChannelsPerFrame = 1;
outputFormat.mBitsPerChannel = 16;
outputFormat.mReserved = 0;
AudioClassDescription *description = [self
getAudioClassDescriptionWithType:kAudioFormatMPEG4AAC
fromManufacturer:kAppleSoftwareAudioCodecManufacturer]; …Run Code Online (Sandbox Code Playgroud) 我正在使用 Android MediaRecorder 来录制 AAC 编码的音频文件。将输出格式设置为 MPEG-4 效果很好。但由于我的音频播放器既不支持 MPEG-4 也不支持 3GP,我尝试使用输出格式AAC_ADTS获取原始 AAC 文件,Android 自 API 级别 16 起就支持该格式。
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
Run Code Online (Sandbox Code Playgroud)
这是我卡住的地方。MediaRecorder 创建了一个文件,但我无法使用任何播放器播放该文件(Android 的 MediaPlayer、Windows Media Player 和我上面提到的音频播放器都无法播放,它能够播放我在网上找到的 ADTS AAC 文件) .
难道我做错了什么?AAC_ADTS 输出格式甚至是值得推荐的格式吗?有没有办法获得 ADIF AAC 文件?