The invention relates to a method for generating an AAC file by coding, which comprises the following steps: step 1, frame data processing: dividing original data to be processed into a plurality of standard data blocks with the size of 4096 bytes according to the size of 4096 bytes, and storing the last nonstandard data blocks with the size less than 4096 bytes; step 2, encoding: sending the standard data block to an AAC coding algorithm for processing; step 3, when new original data to be processed comes, splicing the nonstandard data blocks stored in the step 1 at the initial part of the new original data to be processed, and executing the steps 1 and 2 again; and by analogy, the whole data block with any size is encoded into a complete AAC format file in batches according to the size of one frame. When an audio file in an AAC format is generated by encoding, the invention automatically forms a frame by any size of data sent each time so as to prevent the encoded AAC file from having noise caused by data loss.
Description Method for generating AAC file through codingTechnical Field
The invention relates to the field of digital audio coding and decoding algorithms, in particular to a method for generating an AAC file through coding. In particular to a method for generating an AAC file by automatic framing coding.
Background
In audio processing, there are many cases where an original PCM format audio file (PCM is WAV, and generally, a frame of PCM is composed of 2048 samples) needs to be encoded into an AAC format audio file (AAC file), and in the AAC encoding format, 1024 samples (samples) are required for a frame of audio data, if two-channel audio data is used, 1024 2(4096) bytes are required for a frame of audio data, and if less than one frame of audio data is generated during encoding into the AAC format audio file, for example, less than 4096 bytes are generated for a frame of two-channel audio data, the encoding algorithm discards the frame of audio data, so that in practical applications, each time a block of data delivered to the encoding algorithm cannot be evenly divided by 4096, each block of PCM data with a size that cannot be evenly divided by 4096 will have less than one frame of PCM data discarded, eventually resulting in an incomplete generated AAC file that sounds murky. The specific situations are as follows:
case 1, data block larger than 4096 bytes: the coding algorithm divides the data into a plurality of data blocks equal to 4096 bytes for coding, and discards the remaining data blocks smaller than 4096 bytes;
case 2, a data block smaller than 4096 bytes, the coding algorithm is directly discarded;
case 3, equal to a 4096 byte data block, the encoding algorithm encodes directly.
Since the space of 4096 bytes can be predefined in the prior art when encoding into an AAC format audio file, a frame of data with a fixed size is delivered to the encoding algorithm each time, and the data blocks to be processed in many scenarios in practical application are not all integral multiples of 4096, so the use limitation is very large.
Disclosure of Invention
Aiming at the defects in the prior art, the invention aims to provide a method for encoding and generating an AAC file, which automatically forms data with any size sent each time into a frame when an audio file in an AAC format is encoded and generated so as to prevent the AAC file from having noise after encoding due to data loss.
In order to achieve the above purposes, the technical scheme adopted by the invention is as follows:
a method of encoding an AAC file, comprising the steps of:
step 1, frame data processing: the raw data to be processed is divided into several standard blocks of 4096 bytes in size by 4096 bytes,
storing the last nonstandard data block with the size less than 4096 bytes;
step 2, encoding: sending the standard data block to an AAC coding algorithm for processing;
step 3, when new original data to be processed comes, splicing the nonstandard data blocks stored in the step 1 at the initial part of the new original data to be processed, and executing the steps 1 and 2 again;
and by analogy, the whole data block with any size is encoded into a complete AAC format file in batches according to the size of one frame.
On the basis of the technical scheme, in the step 1, the non-standard data block is stored in the memory.
On the basis of the above technical solution, in step 3, when no new original data to be processed arrives, the stored non-standard data block is discarded.
On the basis of the technical scheme, when the original data to be processed is the PCM data, the PCM data is processed in batches by any data block larger than 4096 bytes.
On the basis of the technical scheme, any data block larger than 4096 bytes is generated by a random algorithm.
The method for generating the AAC file by coding automatically forms data with any size sent each time into a frame when the audio file with the AAC format is generated by coding, so that the AAC file after coding is prevented from having noise caused by data loss.
Drawings
The invention has the following drawings:
FIG. 1 is a flow chart of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings.
The method for generating the AAC file by coding does not need to prepare 4096 bytes of data with fixed size in advance, and can transmit data blocks with any size to an AAC coding algorithm (coding algorithm for short). The method specifically comprises the following conditions:
1. the data block is larger than 4096 and cannot be evenly divided by 4096:
dividing the data block into a plurality of data blocks which are equal to 4096 for coding, and storing the remaining data blocks which are smaller than 4096 for splicing with the next data block; discarding if there is no next data block;
2. the data block is larger than 4096 and can be evenly divided by 4096:
dividing the data block into a plurality of data blocks which are equal to 4096 for encoding;
3. data block equals 4096:
directly sending to a coding algorithm for coding;
4. data block is smaller than 4096:
if the data block is the last data block, because the frame is not enough, the coding algorithm cannot code the error of the returned data which is too small and directly discards the error, otherwise, the error is spliced with the next data block.
The method for generating an AAC file by encoding, as shown in FIG. 1, comprises the following steps:
step 1, frame data processing: the raw data to be processed is divided into several standard blocks of 4096 bytes in size by 4096 bytes,
storing the last nonstandard data block with the size less than 4096 bytes;
step 2, encoding: sending the standard data block to an AAC coding algorithm for processing;
step 3, when new original data to be processed comes, splicing the nonstandard data blocks stored in the step 1 at the initial part of the new original data to be processed, and executing the steps 1 and 2 again;
by analogy, the whole data block (PCM format audio file) with any size is encoded into the complete AAC format file in batches according to the size of one frame (4096 bytes).
On the basis of the technical scheme, in the step 1, the non-standard data block is stored in the memory.
On the basis of the above technical solution, in step 3, when no new original data to be processed arrives, the stored non-standard data block is discarded.
The method of the invention can process the PCM data which needs to be coded into an AAC format file in batches by any data block which is larger than 4096 bytes, automatically frames into a plurality of standard data blocks which are 4096 bytes in size to code AAC, and then codes the complete frame data into an AAC file.
The following are specific examples.
In the singing and up-down-tuning function, an AAC accompaniment file downloaded from a server is decoded into PCM data, then the PCM data is processed by an up-down-tuning algorithm, and then the PCM data and the human voice are mixed and finally encoded into the AAC accompaniment file. The total data size in the processing process of the example is arbitrary, the size of each data is also arbitrary, and the algorithm is finished after the whole decoded AAC file is completely processed. Most of each data in the process is not multiple of 4096, that is, each data is divided into less than one frame, but the data is transmitted to the algorithm of the invention for processing, so that the data is automatically framed and prevented from being discarded until the data is coded into a complete AAC work file.
For example: the total data is 11, 010, 048 bytes, and is divided into 35 data, each data is of any size but larger than 4096 bytes, and any data block larger than 4096 bytes is generated by a random algorithm.
Take the first three data as an example:
the first data: 9876 bytes, the algorithm divides the data into three blocks of 4096, 4096 and 1684, directly encodes the first two blocks of data, and stores the rest 1684 bytes in the memory;
and the second pen data: 10000 bytes, dividing it into 2412, 4096 and 3492, splicing three blocks of data, 2412 and the residual 1684 bytes of the first data into a frame, then coding it with the following second block 4096 bytes of data, and then storing the 3492 third block of data;
and the third stroke of data: 8192 bytes, dividing it into 604, 4096 and 3492 blocks of data, 604 splicing with the last remaining 3492 block into a frame and a second block for encoding, storing 3492,
and so on, each data is processed step by step, and the data processing of the last two strokes is as follows:
the penultimate data: 23456 bytes, dividing into several blocks, the first block may be spliced with the last remaining data into a frame or a frame, i.e. the data is divided into six blocks of 4096, 4096, 4096, 4096, 4096 and 2976 bytes, the first five blocks of data are sequentially coded, and 2976 is stored;
the last data: 10066 bytes, divided into 1120, 4096 and 754 bytes, splicing 1120 and the last but one stroke of the remaining 2976 into one frame, and encoding the two blocks of data sequentially, wherein the last block of data 754 bytes is discarded by the encoding algorithm because it is less than one frame. Obviously, the algorithm only discards 754 bytes of data, and the generated AAC file has good integrity, small loss data and no obvious noise.
Those not described in detail in this specification are within the skill of the art.
Claims (2)1. A method of encoding an AAC file, comprising the steps of:
step 1, frame data processing: the raw data to be processed is divided into several standard blocks of 4096 bytes in size by 4096 bytes,
storing the last nonstandard data block with the size less than 4096 bytes;
when the original data to be processed is PCM data, the PCM data is processed in batches by any data block larger than 4096 bytes;
generating any data block larger than 4096 bytes by a random algorithm;
step 2, encoding: sending the standard data block to an AAC coding algorithm for processing;
step 3, when new original data to be processed comes, splicing the nonstandard data blocks stored in the step 1 at the initial part of the new original data to be processed, and executing the steps 1 and 2 again;
by analogy, the whole data block with any size is encoded into a complete AAC format file in batches according to the size of one frame;
in step 3, when no new original data to be processed comes, the stored nonstandard data block is discarded.
2. The method of encoding an AAC file of claim 1, wherein: in step 1, the non-standard data block is stored in the memory.
CN201611079228.XA 2016-11-30 2016-11-30 Method for generating AAC file through coding Active CN106782573B (en) Priority Applications (1) Application Number Priority Date Filing Date Title CN201611079228.XA CN106782573B (en) 2016-11-30 2016-11-30 Method for generating AAC file through coding Applications Claiming Priority (1) Application Number Priority Date Filing Date Title CN201611079228.XA CN106782573B (en) 2016-11-30 2016-11-30 Method for generating AAC file through coding Publications (2) Family ID=58901069 Family Applications (1) Application Number Title Priority Date Filing Date CN201611079228.XA Active CN106782573B (en) 2016-11-30 2016-11-30 Method for generating AAC file through coding Country Status (1) Families Citing this family (2) * Cited by examiner, â Cited by third party Publication number Priority date Publication date Assignee Title CN110888750B (en) * 2018-09-07 2024-07-05 é¿éå·´å·´é墿§è¡æéå ¬å¸ Data processing method and device CN111262798B (en) * 2018-11-30 2023-03-14 æ·±å³å¸ä¸å ´å¾®çµåææ¯æéå ¬å¸ Information processing method, information processing equipment and computer storage medium Citations (9) * Cited by examiner, â Cited by third party Publication number Priority date Publication date Assignee Title CN1162006A (en) * 1997-02-26 1997-10-15 è¦ææ High-effective gas additive CN1189745A (en) * 1996-10-22 1998-08-05 ç´¢å°¼å ¬å¸ Transmitting apparatus and method, receiving apparatus and method CN1669358A (en) * 2002-07-16 2005-09-14 çå®¶é£å©æµ¦çµåè¡ä»½æéå ¬å¸ Audio coding EP1626504A1 (en) * 2003-05-21 2006-02-15 Sony Corporation Data processing device, encoding device, encoding method, decoding device, decoding method, and program CN102254560A (en) * 2010-05-19 2011-11-23 å®å¯(广å·)å¾®çµåææ¯æéå ¬å¸ Audio processing method in mobile digital television recording US8924207B2 (en) * 2009-07-23 2014-12-30 Texas Instruments Incorporated Method and apparatus for transcoding audio data CN104732979A (en) * 2015-03-24 2015-06-24 æ é¡å¤©èèæºä¼ åªç§ææéå ¬å¸ Processing method and device of audio data CN105070292A (en) * 2015-07-10 2015-11-18 ç æµ·å¸æ°çç§ææéå ¬å¸ Audio file data reordering method and system CN105247614A (en) * 2013-04-05 2016-01-13 ææ¯å½é å ¬å¸ Audio encoder and decoder Family Cites Families (8) * Cited by examiner, â Cited by third party Publication number Priority date Publication date Assignee Title CN100466601C (en) * 2005-04-28 2009-03-04 åä¸ºææ¯æéå ¬å¸ A data reading and writing device and reading and writing method thereof CN100580770C (en) * 2005-08-08 2010-01-13 ä¸å½ç§å¦é¢å£°å¦ç ç©¶æ Speech endpoint detection method based on energy and harmonics CN101345531B (en) * 2008-08-19 2012-12-26 æ é¡ä¸æå¾®çµåæéå ¬å¸ Data processing method for ogg format stream CN102364472A (en) * 2011-10-25 2012-02-29 ä¸å ´é讯è¡ä»½æéå ¬å¸ Data storage method and system CN104050968B (en) * 2014-06-23 2017-02-15 ä¸åå¤§å¦ Embedded type audio acquisition terminal AAC audio coding method CN104795072A (en) * 2015-03-25 2015-07-22 æ é¡å¤©èèæºä¼ åªç§ææéå ¬å¸ Method and device for coding audio data CN104778150B (en) * 2015-03-27 2018-12-14 åä¸ºææ¯æéå ¬å¸ A kind of frequency domain technique and device CN105337617B (en) * 2015-12-09 2018-10-26 æµæ±ç»´èçµåç§æè¡ä»½æéå ¬å¸ A kind of FSN files high-efficiency compression methodRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4