Record 16bps wave file in iOS - objective-c
I am trying to record a wave file and then convert this file to flac in iOS. However, the libflac library always give me the following error:
invalid/unsupported WAVE file, only 16bps stereo WAVE in canonical form allowed
How can I record the file with this kind of properties? These are the properties that I am currently using:
AVFormatIDKey = kAudioFormatLinearPCM
AVSampleRateKey = 16000
AVNumberOfChannelsKey = 2
AVLinearPCMBitDepthKey = 16
AVLinearPCMIsBigEndianKey = NO
AVLinearPCMIsFloatKey = NO
How should I change these properties in order to use libflac?
It turned out that the settings are correct after all. The problem was with the wav file format and libflac. Apple creates a format that is slightly different than the know wave format. That is the reason of the problems that appeared in my case
Apple's wave format has a slightly different header. Check out Jason Hurt's code for converting Apple's waves to FLAC: https://github.com/jhurt/wav_to_flac.
Related
Is there file size limit for the imported .dat file?
I meet a problem for the large stacked images of several GB. Actually, I can directly open a stacked image (dm4 format) of 9GB (1000x1000x1000), but if I want to rotate it using volumn operation such as "rotate about x", the GMS or DM exits automatically. I write a simple script code to complete the operation with the slice3 function and display the result correctly, but I cannot save it! If I try to save the resulted stacked image, software says "sorry" and forces me to close it. OK, I think this file is too large to the software's capability. So I save the original data file to .dat formate and write a fortran code to rotate it, then save the result as a .dat file. When I use the import function of GMS or DM, it only imports first several hundred frames, not all frames. How to deal with it?
There certainly are size restrictions in both total size and maximum length along one dimension, but I don't think 1000 x 1000 x 1000 should be a limiting factor. I just ran the following two scripts in order and saved the data on my GMS 3.4.3 without problem. image big := RealImage("Big First",4,1000,1000,1000) big = icol*sin(irow/iheight*100*pi())*10000+iplane big.showimage() image bigIn := A image bigOut := bigIn.Slice3(0,0,0, 1,1000,1,0,1000,1,2,1000,1) bigOut.ShowImage() Can you edit you question to include the script code you're failing to run and other useful information?
MTKTextureLoader messes PNG RGB vs BGR formats
I'm trying to port my OpenGL code to Metal one. As part of it I need to draw PNG textures, and I'm using MTKTextureLoader to load them. Here is my pipeline code: texturePipelineDescriptor.vertexFunction = textureVertexFunc; texturePipelineDescriptor.fragmentFunction = textureFragmentFunc; texturePipelineDescriptor.colorAttachments[0].pixelFormat = MTLPixelFormatRGBA8Unorm; texturePipelineDescriptor.colorAttachments[0].blendingEnabled = YES; texturePipelineDescriptor.colorAttachments[0].rgbBlendOperation = MTLBlendOperationAdd; texturePipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = MTLBlendFactorSourceAlpha; texturePipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = MTLBlendFactorOneMinusSourceAlpha; And here is my loader code: NSData* imageData = [NSData dataWithBytes:imageBuffer length:imageBufferSize]; id<MTLTexture> newMTLTexture = [m_metal_renderer.metalTextureLoader newTextureWithData:imageData options:nil error:&error]; And here is the result. The entire image should be orange, like the small parts. If I change this line: texturePipelineDescriptor.colorAttachments[0].pixelFormat = MTLPixelFormatRGBA8Unorm; To this line: texturePipelineDescriptor.colorAttachments[0].pixelFormat = MTLPixelFormatBGRA8Unorm; I will get the following results: As you can see,images changed R and B channels, When I loading the textures, in ALL OF THEM newMTLTexture.pixelFormat = MTLPixelFormatBGRA8Unorm; regardless whether they are drawn correctly or not. I would suspect there is something wrong with PNG files, but they seems absolutely normal in any PNG viewer. Any clues what I can do to resolve it? Is it a bug In MTLTextureLoader? Is there another way of loading PNG picture? P.S. The software is written for MacOS and not iOS.
I found the problem. It seems that some of the PNG files were stored in RGB (24 bit) format, while another were stored in RGBA (32 bit) format. All color became right after converting images to 32bit format. I would expect MTKTextureLoader to be able to handle that, but apparently it is not. If someone knows the option I missed or another way to correctly load those PNG's to Metal (Other than adding 4th channel manually) it will be great!
How do I read the position data from a GPS (NMEA) device?
I'm trying to read data from a GPS device (NMEA). I am getting the data successfully. However, as soon as I start using it, it gives me gibbirish. This is what I get from the GPS: $GPGSA,A,3,20,25,31,22,14,29,03,16,32,06,27,,1.5,0.8,1.3*33 $GPRMC,120556.000,A,2546.0985,S,02816.0193,E,0.22,276.44,291013,,,A*7A $GPGGA,120557.000,2546.0984,S,02816.0191,E,1,11,0.8,1396.3,M,21.5,M,,0000*71 $GPGSA,A,3,20,25,31,22,14,29,03,16,32,06,27,,1.5,0.8,1.3*33 $GPGSV,3,1,12,31,50,165,19,14,48,055,27,16,43,304,42,32,36,265,38*76 $GPGSV,3,2,12,29,24,119,31,06,19,355,34,20,14,238,41,25,10,138,19*78 $GPGSV,3,3,12,27,09,351,33,22,06,008,36,03,05,341,36,23,,221,*7F $GPRMC,120557.000,A,2546.0984,S,02816.0191,E,0.17,274.76,291013,,,A*7D $GPGGA,120558.000,2546.0982,S,02816.0189,E,1,11,0.8,1396.0,M,21.5,M,,0000*72 $GPGSA,A,3,20,25,31,22,14,29,03,16,32,06,27,,1.5,0.8,1.3*33 $GPRMC,120558.000,A,2546.0982,S,02816.0189,E,0.07,220.52,291013,,,A*7B $GPGGA,120559.000,2546.0981,S,02816.0187,E,1,11,0.8,1395.7,M,21.5,M,,0000*7A $GPGSA,A,3,20,25,31,22,14,29,03,16,32,06,27,,1.5,0.8,1.3*33 $GPRMC,120559.000,A,2546.0981,S,02816.018 The above was received by doing the following: //inside a 100ms ticker Dim data As String = GpsPort.ReadExisting() CommentBox.AppendText(data) As soon as I do Dim strArr() As String = data.Split("$") then output it using: CommentBox.AppendText(strArr(0).ToString) // inside the same ticker the output is: 034.000,2546.0985,S,02816.0298,E,1,11,0.8,1360.6,M,21.5,M,,0000*77 3,20,29,14,22,31,25,03,16,32,06,27,,1.5,0.8,1.3*33 MC,121034.000,A,2546.0985,S,02816.0298,E,0.01,236.13,291013,,,A*75 .000,2546.0983,S,02816.0297,E,1,11,0.8,1359.9,M,21.5,M,,0000*7A A,A,3,20,29,14,22,31,25,03,16,32,06,27,,1.5,0.8,1.3*33 ,121035.000,A,2546.0983,S,02816.0297,E,0.06,283.04,291013,,,A*72 036.000,2546.0982,S,02816.0296,E,1,11,0.8,1359.3,M,21.5,M,,0000*73 3,20,29,14,22,31,25,03,16,32,06,27,,1.5,0.8,1.3*33 MC,121036.000,A,2546.0982,S,02816.0296,E,0.03,190.30,291013,,,A*72 .000,2546.0981,S,02816.0296,E,1,11,0.8,1358.6,M,21.5,M,,0000*75 A,A,3,20,29,14,22,31,25,03,16,32,06,27,,1.5,0.8,1.3*33 3,1,12,31,49,161,28,14,46,052,20,16,45,301,39,32,36,268,35*79 3,2,12,29,23,122,18,06,21,355,27,20,15,240,40,27,11,351,37*78 Can anyone assist me in getting the GPS co-ordinates from the GPGGA strings? Because splitting them clearly doesn't work.
You have to read the data line by line. Each line is one NMEA sentence. Once you detect "$GPGGA" (or you also could use the RMC message) you have this line: $GPGGA,120557.000,2546.0984,S,02816.0191,E,1,11,0.8,1396.3,M,21.5,M,,0000*71 Now you splitt by delimiter "," Then this is latitude : 2546.0984,S And this is longitude 02816.0191,E read at NMEA spec which format the coordinates are: I think: the first to digits in latitdue are degrees, the rest is minutes: 25° 46.0984 minutes. If "S" multiply the result with -1. slightly different for longitude: 02816.0191,E first 3 digits degrees, rest minutes. 27° 16.0191 minutes. multiply with -1 if "W".
Basically, the messages you are seeing are part of a rather complicated message format. Each part means something different and the meanings depend on the message type. You may want to look at some of the code in this open source project. I wrote this library with a colleague and it parses out those messages from a specific GPS device, but it should work with pretty much any device putting out the same data.
How to get supported pixel format of video capture device (camera) in mac os x
Just now i start a small work related to video capture I want all supported pixel formats by a video capture device using avfoundation. I am using CMFormatDescriptionGetMediaSubtype function to get pixel format in mac(CMPixelFormatType). But i am always getting a value which is not matching from any of the available pixel format (predefined pixel fromat like: kCMPixelFormat_422YpCbCr8_yuvs). Is there any other function present for that purpose.. I searched but till now not found. Returned value is always 1684890161 as pixel format type. Actual thing I want to ask is : How can I have all supported pixel formats by a video capture device in Mac. Remember I am not asking for codec type. Its pixel format I need. Please help.. if possible. Thanks in advance..
To get all supported pixel formats, you need to call CMIOObjectGetPropertyData with the second parameter CMIOObjectPropertyAddress as follows: CMIOObjectPropertyAddress theAddress; theAddress.mSelector = kCMIOStreamPropertyFormatDescriptions; theAddress.mScope = kCMIOObjectPropertyScopeGlobal; theAddress.mElement = 0; This will give you a CFArray of CMFormatDescriptionRef. Then you iterate over this array and call: CMFormatDescriptionGetMediaSubType(yourCMFormatDescriptionRef); Your CMFormatDescriptionGetMediaSubType translates into a FourCharacterCode (OSType) of 'dmb1' which seems to be a Matrox specific hardware compression type. The reason, you won't find your format in the CMPixelFormatType enum is because there are only the most common formats there, which yours is not. The most common on the Mac are kCMPixelFormat_422YpCbCr8 and kCMPixelFormat_422YpCbCr10, both are raw 8 and 10 bit YUV video.
Extract floats with Extended Audio File Services (ExtAudioFileRead)
I'm trying to write a program to log the float values of samples in an audio file. My steps are as follows: Open an Extended Audio File Set up audio format (AudioStreamBasicDescription) Apply audio format to my Extended Audio File Set up an AudioBufferList Read Extended Audio File into AudioBufferList with ExtAudioFileRead() Log float values of AudioBufferList I've put the entire 90 line class in this gist: https://gist.github.com/792630 The trouble is, if I apply an audio format to my Extended Audio File (Step 3), I get an error trying to read the file (Step 5). If I comment out step 5, the file reads fine but I will not have enforced my format for the read and I don't get floats when logging. Any suggestions would be greatly appreciated. Thanks!
One thing I noticed right away is that you are allocating an AudioBufferList on the stack but setting mNumberBuffers to 2. It's fine to use ABLs on the stack, but if you do that they can only ever contain one buffer. But since you've set the client format to mono that isn't your real problem. The real problem is that you aren't passing the address of fileRef to ExtAudioFileOpenURL- you're passing the value- so there is no way that the call can initialize the variable properly. The call should look like this: CheckResult(ExtAudioFileOpenURL(inputFileURL, &fileRef), "ExtAudioFileOpenURL failed"); I did that, compiled your code and everything worked fine.