mã sau được lấy từ Apple's Sample AVRecorder
… bit cụ thể này mua một tập hợp các kết nối từ phương thức kết nối movieFileOutput của lớp này, nhận AVCaptureAudioChannel cho mỗi kết nối và tính toán công suất decibel dựa trên đó. tôi sẽ đoán rằng nếu bạn đang tìm kiếm một "mức độ tiếng ồn" đầu ra, bạn sẽ có thể nắm bắt thông tin tương tự. nếu bạn đang tìm kiếm thứ gì đó thấp hơn mức này, hãy thử khung công tác HAL (Hardware Abstraction Layer).
- (void)updateAudioLevels:(NSTimer *)timer
{
NSInteger channelCount = 0;
float decibels = 0.f;
// Sum all of the average power levels and divide by the number of channels
for (AVCaptureConnection *connection in [[self movieFileOutput] connections]) {
for (AVCaptureAudioChannel *audioChannel in [connection audioChannels]) {
decibels += [audioChannel averagePowerLevel];
channelCount += 1;
}
}
decibels /= channelCount;
[[self audioLevelMeter] setFloatValue:(pow(10.f, 0.05f * decibels) * 20.0f)];
}
Nguồn
2012-08-13 05:37:10
Chuyển đổi đó không phải là pow (10.f, 0.05f * decibels)? bạn không cần thêm 20 lần nữa. đọc tại đây: http://stackoverflow.com/questions/2465328/iphone-sdk-avaudiorecorder-metering-how-to-change-peakpowerforchannel-from-d hoặc tốt hơn nhưng http://travisjeffery.com/b/2013/02/conversion-avfoundations-power-levels-to-from-logarit-và-tuyến-quy mô/ – ucangetit
@ucangetit, tôi không thể nói một cách thông minh đến từng chi tiết liên quan đến đoạn mã. tôi chỉ sao chép mã trong trường hợp Apple sửa đổi liên kết đến mã mẫu. –