AQA GCSE Computer Science June 2022 Paper 1, Question 11: the sound file size subroutine
AQA 8525 June 2022 Paper 1, Question 11: fill six gaps in a subroutine that works out the size of a sound file in bytes, then explain local variables and the advantages of subroutines. Worked through, with the subroutine to run.
Question 11 of the AQA GCSE Computer Science June 2022 Paper 1 (8525/1B, the Python paper) joins two topics: the sound file size formula from Paper 2, and subroutines with parameters and return values. Part 1 is six gaps to fill (6 marks). Parts 2 and 3 are about local variables (1 mark) and why subroutines are used (3 marks).
We do not copy the exam paper here. Open it beside this page: AQA June 2022 Paper 1B question paper (PDF). When you have finished, check the mark scheme too.
The question in short
The size of a sound file in bits is the sampling rate times the sample resolution times the number of seconds. Divide by 8 for bytes.
A subroutine called getSize should work that out, and the main program should output the size of a file sampled 100 times a second at 16 bits for 60 seconds. Six parts of the pseudo-code are blank. You fill them from a grid of sixteen items, and you will not need them all.
The skeleton looks like this, with each gap shown as a number:
SUBROUTINE getSize(1,2, seconds)- 3
← sampRate * res * seconds size ←4- 5
size ENDSUBROUTINEOUTPUT6(100, 16, 60)
Work it through
Gaps 1 and 2 are sampRate and res. Look at the line below the heading. It uses sampRate, res and seconds. seconds is already a parameter, so the other two must be the missing ones. The order matters: the call passes 100, 16, 60, which is rate, resolution, seconds. rate is in the grid to tempt you, but the body of the subroutine never uses that name.
Gap 3 is size. The next line starts size ← and uses it, so this is where size first gets its value: the number of bits.
Gap 4 is size / 8. Bits to bytes is divide by 8. Not size * 8, which goes the wrong way. Not size MOD 8, which is the remainder.
Gap 5 is RETURN. The main program does the outputting, so the subroutine must hand the value back. If the subroutine used OUTPUT here, the OUTPUT on the last line would have nothing to show.
Gap 6 is getSize. It is the call to the subroutine.
The finished algorithm
| Gap | Answer |
|---|---|
| 1 | sampRate |
| 2 | res |
| 3 | size |
| 4 | size / 8 |
| 5 | RETURN |
| 6 | getSize |
One mark each. Gaps 1 and 2 must be that way round.
Part 2: what is a local variable?
A variable that can only be used inside the subroutine where it is made. Or: a variable that only exists while the subroutine is running. Either gets the mark.
Part 3: three advantages of subroutines
Any three, one mark each:
- they can be written and tested on their own;
- errors are easier to find, because each subroutine can be tested separately;
- the code is easier to understand;
- a team can work on different subroutines at the same time;
- code can be reused, in this program or another one.
Where the marks are lost
res, sampRate. Parameters are matched by position. The call sends 100 first, and 100 is the sampling rate.OUTPUTfor gap 5. Check the last line: it outputs whatevergetSizegives back. That needsRETURN.- "A local variable is inside a subroutine." Say what that means: it cannot be used outside it.
- The same advantage three times. "Easier to read", "easier to understand" and "clearer" are one point, not three.
Run it
The subroutine in Python. Change the three numbers in the call and predict the size first.
The program
from bugbot import *
connect()
def get_size(samp_rate, res, seconds):
size = samp_rate * res * seconds
size = size / 8
return size
print(get_size(100, 16, 60))
# CD quality for a three minute song, in megabytes
print(get_size(44100, 16, 180) * 2 / 1000000, "MB in stereo")
# size is local: it does not exist out here
try:
print(size)
except NameError:
print("size is local to get_size, so this line cannot see it")
Questions
What are the answers to AQA GCSE Computer Science 2022 Paper 1 Question 11.1?
The gaps are sampRate, res, size, size / 8, RETURN and getSize, in that order.
How do you calculate the size of a sound file?
Multiply the sampling rate by the sample resolution by the length in seconds to get the size in bits. Divide by 8 for bytes.
What is the difference between RETURN and OUTPUT in a subroutine?
OUTPUT shows a value to the user. RETURN passes a value back to the code that called the subroutine, so that it can be stored, used in a calculation or output there.
What is a local variable?
A local variable is declared inside a subroutine. It exists only while the subroutine runs and cannot be accessed from outside it.
More from this paper
Every AQA 8525 question we have worked · Guide: Sound sampling explained
Learn it step by step
- F4.2 Parameters and return values Functions and structured code
- F4.3 Local and global variables Functions and structured code
- F8.8 Sound Data representation
This is our own explanation of a published exam question. It is not written or endorsed by AQA, and the question paper and mark scheme remain AQA's copyright. Read them on AQA's site with the links on this page.